Exemplo n.º 1
0
 public function add($data, $parameters = array())
 {
     global $DB, $USER;
     $result = array();
     if (!$USER->IsAuthorized()) {
         throw new Tasks\Exception("Authentication is required.");
     }
     $title = isset($data["title"]) ? trim($data["title"]) : "";
     $responsible = isset($data["responsible"]) ? intval($data["responsible"]) : $USER->GetID();
     $deadline = isset($data["deadline"]) && $DB->FormatDate($data["deadline"], \CSite::GetDateFormat("FULL")) ? $data["deadline"] : "";
     $description = isset($data["description"]) ? trim($data["description"]) : "";
     $project = isset($data["project"]) ? intval($data["project"]) : 0;
     $nameTemplate = isset($data["nameTemplate"]) ? trim($data["nameTemplate"]) : "";
     $ganttMode = isset($data["ganttMode"]) && $data["ganttMode"] === "true";
     if (strlen($nameTemplate) > 0) {
         preg_match_all("/(#NAME#)|(#NOBR#)|(#\\/NOBR#)|(#LAST_NAME#)|(#SECOND_NAME#)|(#NAME_SHORT#)|(#SECOND_NAME_SHORT#)|\\s|\\,/", $nameTemplate, $matches);
         $nameTemplate = implode("", $matches[0]);
     } else {
         $nameTemplate = \CSite::GetNameFormat(false);
     }
     $fields = array("TITLE" => $title, "DESCRIPTION" => $description, "RESPONSIBLE_ID" => $responsible, "DEADLINE" => $deadline, "SITE_ID" => $data["siteId"], "GROUP_ID" => $project, "NAME_TEMPLATE" => $nameTemplate, 'DESCRIPTION_IN_BBCODE' => "Y");
     $taskItem = \CTaskItem::add($fields, $USER->GetId());
     $task = $taskItem->getData();
     $task["GROUP_NAME"] = "";
     if ($task["GROUP_ID"]) {
         $socGroup = \CSocNetGroup::GetByID($task["GROUP_ID"]);
         if ($socGroup) {
             $task["GROUP_NAME"] = $socGroup["~NAME"];
         }
     }
     \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "TASK_RESPONSIBLE", "CODE" => array("U" . $task["RESPONSIBLE_ID"], "SG" . $task["GROUP_ID"])));
     $taskId = $taskItem->getId();
     $arPaths = array("PATH_TO_TASKS_TASK" => isset($data["pathToTask"]) ? trim($data["pathToTask"]) : "", "PATH_TO_USER_PROFILE" => isset($data["pathToUser"]) ? trim($data["pathToUser"]) : "", "PATH_TO_USER_TASKS_TASK" => isset($data["pathToUserTasksTask"]) ? trim($data["pathToUserTasksTask"]) : "");
     $columnsOrder = null;
     if (isset($data["columnsOrder"]) && is_array($data["columnsOrder"])) {
         $columnsOrder = array_map("intval", $data["columnsOrder"]);
     }
     $order = isset($data["order"]) && checkSerializedData($data["order"]) ? unserialize($data["order"]) : array();
     $filter = isset($data["filter"]) && checkSerializedData($data["filter"]) ? unserialize($data["filter"]) : array();
     $navigation = isset($data["navigation"]) && checkSerializedData($data["navigation"]) ? unserialize($data["navigation"]) : array();
     $select = isset($data["select"]) && checkSerializedData($data["select"]) ? unserialize($data["select"]) : array();
     $result["taskRaw"] = $task;
     $result["taskId"] = $task["ID"];
     $result["taskPath"] = \CComponentEngine::MakePathFromTemplate($arPaths["PATH_TO_TASKS_TASK"], array("task_id" => $task["ID"], "action" => "view"));
     $result["position"] = $this->getTaskPosition($taskId, $order, $filter, $navigation, $select);
     if ($ganttMode) {
         $result["task"] = $this->getJson($task, $arPaths, $nameTemplate);
     } else {
         $result["html"] = $this->getHtml($task, $arPaths, $nameTemplate, $columnsOrder);
     }
     return $result;
 }
Exemplo n.º 2
0
 public static function merge($data)
 {
     static $connection = false;
     static $helper = false;
     if (!$connection) {
         $connection = \Bitrix\Main\Application::getConnection();
         $helper = $connection->getSqlHelper();
     }
     $userId = isset($data['USER_ID']) && intval($data['USER_ID']) > 0 ? intval($data['USER_ID']) : $GLOBALS['USER']->getId();
     if (is_array($data['CODE'])) {
         $dataModified = $data;
         foreach ($data['CODE'] as $code) {
             $dataModified['CODE'] = $code;
             FinderDestTable::merge($dataModified);
         }
         return;
     } else {
         $insertFields = array('USER_ID' => $userId, 'CODE' => strtoupper($data['CODE']), 'CONTEXT' => isset($data['CONTEXT']) ? strtoupper($data['CONTEXT']) : '', 'LAST_USE_DATE' => new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction()));
         if (preg_match('/^U(\\d+)$/i', $data['CODE'], $matches)) {
             $insertFields['CODE_USER_ID'] = intval($matches[1]);
             $insertFields['CODE_TYPE'] = 'U';
         } elseif (preg_match('/^SG(\\d+)$/i', $data['CODE'], $matches)) {
             $insertFields['CODE_TYPE'] = 'SG';
         } elseif (preg_match('/^D(\\d+)$/i', $data['CODE'], $matches) || preg_match('/^DR(\\d+)$/i', $data['CODE'], $matches)) {
             $insertFields['CODE_TYPE'] = 'D';
         } elseif (preg_match('/^CRMCONTACT(\\d+)$/i', $data['CODE'], $matches) || preg_match('/^CRMCOMPANY(\\d+)$/i', $data['CODE'], $matches) || preg_match('/^CRMDEAL(\\d+)$/i', $data['CODE'], $matches) || preg_match('/^CRMLEAD(\\d+)$/i', $data['CODE'], $matches)) {
             $insertFields['CODE_TYPE'] = 'CRM';
         }
         $merge = $helper->prepareMerge('b_finder_dest', array('USER_ID', 'CODE'), $insertFields, array('LAST_USE_DATE' => new \Bitrix\Main\DB\SqlExpression($helper->getCurrentDateTimeFunction())));
         if ($merge[0] != "") {
             $connection->query($merge[0]);
         }
         $cache = new \CPHPCache();
         $cache->cleanDir('/sonet/log_dest_sort/' . intval($userId / 100));
     }
 }
Exemplo n.º 3
0
                 } else {
                     CSocNetLog::Update($arRes["ID"], array("=LOG_UPDATE" => $DB->CurrentTimeFunction()));
                 }
                 /* subscribe share author */
                 CSocNetLogFollow::Set($user_id, "L" . $arRes["ID"], "Y", ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL"));
             }
             /* update socnet groupd activity*/
             foreach ($arNewRights as $v) {
                 if (substr($v, 0, 2) == "SG") {
                     $group_id_tmp = substr($v, 2);
                     if (IntVal($group_id_tmp) > 0) {
                         CSocNetGroup::SetLastActivity(IntVal($group_id_tmp));
                     }
                 }
             }
             \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "blog_post", "CODE" => \Bitrix\Main\FinderDestTable::convertRights($arNewRights)));
         }
     }
     die;
 }
 /* end share */
 if (!$arResult["bFromList"]) {
     $strTitle = $arPost["MICRO"] != "Y" ? $arPost["TITLE"] : TruncateText(blogTextParser::killAllTags($arPost["DETAIL_TEXT"]), 100);
     if (IsModuleInstalled("intranet")) {
         $APPLICATION->SetPageProperty("title", $strTitle);
     } else {
         $APPLICATION->SetTitle($strTitle);
     }
 }
 if ($arParams["SET_NAV_CHAIN"] == "Y") {
     $APPLICATION->AddChainItem($arBlog["NAME"], CComponentEngine::MakePathFromTemplate(htmlspecialcharsback($arParams["PATH_TO_BLOG"]), array("blog" => $arBlog["URL"], "user_id" => $arPost["AUTHOR_ID"], "group_id" => $arParams["SOCNET_GROUP_ID"])));
Exemplo n.º 4
0
 public static function SendMentionNotification($arCommentFields)
 {
     if (!CModule::IncludeModule("im")) {
         return false;
     }
     switch ($arCommentFields["EVENT_ID"]) {
         case "forum":
             $arTitleRes = self::OnSendMentionGetEntityFields_Forum($arCommentFields);
             break;
         default:
             $db_events = GetModuleEvents("socialnetwork", "OnSendMentionGetEntityFields");
             while ($arEvent = $db_events->Fetch()) {
                 $arTitleRes = ExecuteModuleEventEx($arEvent, array($arCommentFields));
                 if ($arTitleRes) {
                     break;
                 }
             }
     }
     if ($arTitleRes && is_array($arTitleRes) && !empty($arTitleRes["NOTIFY_MESSAGE"])) {
         $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $arCommentFields["USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => !empty($arTitleRes["NOTIFY_MODULE"]) ? $arTitleRes["NOTIFY_MODULE"] : "socialnetwork", "NOTIFY_EVENT" => "mention", "NOTIFY_TAG" => !empty($arTitleRes["NOTIFY_TAG"]) ? $arTitleRes["NOTIFY_TAG"] : "LOG_COMMENT|COMMENT_MENTION|" . $arCommentFields["ID"]);
         preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/ies" . BX_UTF_PCRE_MODIFIER, $arCommentFields["MESSAGE"], $arMention);
         if (!empty($arMention)) {
             $arMention = $arMention[1];
             $arExcludeUsers = array();
             if (!empty($arCommentFields["LOG_ID"])) {
                 $rsUnFollower = CSocNetLogFollow::GetList(array("CODE" => "L" . $arCommentFields["LOG_ID"], "TYPE" => "N"), array("USER_ID"));
                 while ($arUnFollower = $rsUnFollower->Fetch()) {
                     $arExcludeUsers[] = $arUnFollower["USER_ID"];
                 }
             }
             $arSourceURL = array("URL" => $arTitleRes["URL"]);
             if (!empty($arTitleRes["CRM_URL"])) {
                 $arSourceURL["CRM_URL"] = $arTitleRes["CRM_URL"];
             }
             foreach ($arMention as $mentionUserID) {
                 $bHaveRights = CSocNetLogRights::CheckForUserOnly($arCommentFields["LOG_ID"], $mentionUserID);
                 if (!$bHaveRights && $arTitleRes["IS_CRM"] == "Y") {
                     $dbLog = CSocNetLog::GetList(array(), array("ID" => $arCommentFields["LOG_ID"], "ENTITY_TYPE" => $arCommentFields["ENTITY_TYPE"]), false, false, array("ID"), array("IS_CRM" => "Y", "CHECK_CRM_RIGHTS" => "Y", "USER_ID" => $mentionUserID, "USE_SUBSCRIBE" => "N"));
                     if ($arLog = $dbLog->Fetch()) {
                         $bHaveCrmRights = true;
                     }
                 }
                 if (in_array($mentionUserID, $arExcludeUsers) || !$bHaveRights && !$bHaveCrmRights) {
                     continue;
                 }
                 $url = false;
                 if (!empty($arSourceURL["URL"]) || !empty($arSourceURL["CRM_URL"])) {
                     $arTmp = CSocNetLogTools::ProcessPath($arSourceURL, $mentionUserID);
                     if ($arTitleRes["IS_CRM"] == "Y" && !$bHaveRights && !empty($arTmp["URLS"]["CRM_URL"])) {
                         $url = $arTmp["URLS"]["CRM_URL"];
                     } else {
                         $url = $arTmp["URLS"]["URL"];
                     }
                     $serverName = strpos($url, "http://") === 0 || strpos($url, "https://") === 0 ? "" : $arTmp["SERVER_NAME"];
                 }
                 $arMessageFields["TO_USER_ID"] = $mentionUserID;
                 $arMessageFields["NOTIFY_MESSAGE"] = str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE"]);
                 $arMessageFields["NOTIFY_MESSAGE_OUT"] = !empty($arTitleRes["NOTIFY_MESSAGE_OUT"]) ? str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE_OUT"]) : "";
                 CIMNotify::Add($arMessageFields);
             }
             $arMentionedDestCode = array();
             foreach ($arMention as $val) {
                 $arMentionedDestCode[] = "U" . $val;
             }
             \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "mention", "CODE" => array_unique($arMentionedDestCode)));
         }
     }
 }
Exemplo n.º 5
0
 public static function GetDestinationSort($arParams = array())
 {
     $arResult = array();
     $userId = isset($arParams["USER_ID"]) && intval($arParams["USER_ID"]) > 0 ? intval($arParams["USER_ID"]) : false;
     $arContextFilter = isset($arParams["CONTEXT_FILTER"]) && is_array($arParams["CONTEXT_FILTER"]) ? $arParams["CONTEXT_FILTER"] : false;
     if (!$userid) {
         if ($GLOBALS["USER"]->IsAuthorized()) {
             $userId = $GLOBALS["USER"]->GetId();
         } else {
             return $arResult;
         }
     }
     $cacheTtl = defined("BX_COMP_MANAGED_CACHE") ? 3153600 : 3600 * 4;
     $cacheId = 'dest_sort' . $userId . serialize($arParams);
     $cacheDir = '/sonet/log_dest_sort/' . intval($userId / 100);
     $obCache = new CPHPCache();
     if ($obCache->InitCache($cacheTtl, $cacheId, $cacheDir)) {
         $arDestAll = $obCache->GetVars();
     } else {
         $obCache->StartDataCache();
         $arFilter = array("USER_ID" => $GLOBALS["USER"]->GetId());
         if (!empty($arParams["CODE_TYPE"])) {
             $arFilter["=CODE_TYPE"] = strtoupper($arParams["CODE_TYPE"]);
         } elseif (!empty($arParams["DEST_CONTEXT"]) && strtoupper($arParams["DEST_CONTEXT"]) != 'CRM_POST') {
             $arFilter["!=CODE_TYPE"] = "CRM";
         }
         if (is_array($arContextFilter) && !empty($arContextFilter)) {
             $arFilter["CONTEXT"] = $arContextFilter;
         }
         $arRuntime = array();
         $arOrder = array();
         if (!empty($arParams["DEST_CONTEXT"])) {
             $conn = \Bitrix\Main\Application::getConnection();
             $helper = $conn->getSqlHelper();
             $arRuntime = array(new \Bitrix\Main\Entity\ExpressionField('CONTEXT_SORT', "CASE WHEN CONTEXT = '" . $helper->forSql($arParams["DEST_CONTEXT"]) . "' THEN 1 ELSE 0 END"));
             $arOrder = array('CONTEXT_SORT' => 'DESC');
         }
         $arOrder['LAST_USE_DATE'] = 'DESC';
         $rsDest = \Bitrix\Main\FinderDestTable::getList(array('order' => $arOrder, 'filter' => $arFilter, 'group' => array("USER_ID"), 'select' => array('CONTEXT', 'CODE', 'LAST_USE_DATE'), 'runtime' => $arRuntime));
         $arDestAll = array();
         while ($arDest = $rsDest->Fetch()) {
             $arDest["LAST_USE_DATE"] = MakeTimeStamp($arDest["LAST_USE_DATE"]->toString());
             $arDestAll[] = $arDest;
         }
         $obCache->EndDataCache($arDestAll);
     }
     foreach ($arDestAll as $arDest) {
         if (!isset($arResult[$arDest["CODE"]])) {
             $arResult[$arDest["CODE"]] = array();
         }
         $contextType = isset($arParams["DEST_CONTEXT"]) && $arParams["DEST_CONTEXT"] == $arDest["CONTEXT"] ? "Y" : "N";
         if ($contextType == "Y" || !isset($arResult[$arDest["CODE"]]["N"]) || $arDest["LAST_USE_DATE"] > $arResult[$arDest["CODE"]]["N"]) {
             $arResult[$arDest["CODE"]][$contextType] = $arDest["LAST_USE_DATE"];
         }
     }
     return $arResult;
 }
Exemplo n.º 6
0
     $arUsrS = array();
     if (!empty($arPSR["U"])) {
         foreach ($arPSR["U"] as $k => $v) {
             $arUsrS[] = "U" . $k;
         }
     }
     preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/is" . BX_UTF_PCRE_MODIFIER, $_POST['comment'], $arMention);
     $arFieldsIM = array("TYPE" => "COMMENT", "TITLE" => htmlspecialcharsBack($arPost["TITLE"]), "URL" => $commentUrl, "ID" => $arPost["ID"], "FROM_USER_ID" => $user_id, "TO_USER_ID" => array($arPost["AUTHOR_ID"]), "TO_SOCNET_RIGHTS" => $arUsrS, "TO_SOCNET_RIGHTS_OLD" => array("U" => array(), "SG" => array()), "AUTHOR_ID" => $arPost["AUTHOR_ID"], "BODY" => $text4mail);
     if (!empty($arMention)) {
         $arFieldsIM["MENTION_ID"] = $arMention[1];
         if ($_POST["act"] != "edit" && is_array($arMention[1]) && !empty($arMention[1])) {
             $arMentionedDestCode = array();
             foreach ($arMention[1] as $val) {
                 $arMentionedDestCode[] = "U" . $val;
             }
             \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "mention", "CODE" => array_unique($arMentionedDestCode)));
         }
     }
     $arFieldsIM["EXCLUDE_USERS"] = array();
     $rsUnFollower = CSocNetLogFollow::GetList(array("CODE" => "L" . $log_id, "TYPE" => "N"), array("USER_ID"));
     while ($arUnFollower = $rsUnFollower->Fetch()) {
         $arFieldsIM["EXCLUDE_USERS"][$arUnFollower["USER_ID"]] = $arUnFollower["USER_ID"];
     }
     CBlogPost::NotifyIm($arFieldsIM);
 }
 $res = CBlogImage::GetList(array(), array("POST_ID" => $arPost["ID"], "BLOG_ID" => $arBlog["ID"], "IS_COMMENT" => "Y", "COMMENT_ID" => false, "<=TIMESTAMP_X" => ConvertTimeStamp(AddToTimeStamp(array("HH" => -3)), "FULL")));
 while ($aImg = $res->Fetch()) {
     CBlogImage::Delete($aImg["ID"]);
 }
 if (strlen($arFields["PUBLISH_STATUS"]) > 0 && $arFields["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH) {
     $arResult["MESSAGE"] = GetMessage("B_B_PC_MES_HIDDEN_ADDED");
Exemplo n.º 7
0
 if (array_key_exists("NEW_INVITE_FORM", $_POST) && $_POST["NEW_INVITE_FORM"] == "Y") {
     // new form
     $arUserIDs = array();
     $arUserCodes = array();
     $arUserCodesFromPost = is_array($_POST["USER_CODES"]) ? $_POST["USER_CODES"] : array($_POST["USER_CODES"]);
     foreach ($arUserCodesFromPost as $user_code) {
         if (preg_match('/^U(\\d+)$/', $user_code, $match)) {
             if (!in_array($match[1], $arUserIDs)) {
                 $arUserIDs[] = $match[1];
             }
             if (!array_key_exists('U' . $match[1], $arUserCodes)) {
                 $arUserCodes['U' . $match[1]] = 'users';
             }
         }
     }
     \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "group_invite", "CODE" => array_keys($arUserCodes)));
     $arResult["POST"]["USER_IDS"] = $arUserIDs;
     $arResult["POST"]["USER_CODES"] = $arUserCodes;
     if ($arResult["bExtranetInstalled"] && array_key_exists("EMAILS", $_POST)) {
         $arResult["POST"]["EMAILS"] = $_POST["EMAILS"];
     }
     if (array_key_exists("TAB", $arResult) && $arResult["TAB"] == "invite" && empty($arUserIDs) && !$arResult["bIntranet"]) {
         $errorMessage .= GetMessage("SONET_GCE_NO_USERS") . ". ";
         $arResult["ErrorFields"][] = "USERS";
     }
 } else {
     // old form
     if ($arResult["bIntranet"]) {
         if (is_array($_POST["USER_IDS"]) && count($_POST["USER_IDS"]) > 0) {
             $arResult["POST"]["USER_IDS"] = $_POST["USER_IDS"];
         }
Exemplo n.º 8
0
 public static function RequestToSonetGroups($arUserId, $arGroupCode, $arGroupName, $bExtranetUser = false)
 {
     $arGroupToAdd = array();
     $strError = false;
     if (!is_array($arUserId)) {
         $arUserId = array($arUserId);
     }
     if (is_array($arGroupCode) && !empty($arGroupCode) && CModule::IncludeModule("socialnetwork")) {
         foreach ($arGroupCode as $group_code) {
             if ($bExtranetUser && preg_match('/^(SGN\\d+)$/', $group_code, $match) && is_array($arGroupName) && isset($arGroupName[$match[1]]) && strlen($arGroupName[$match[1]]) > 0 && CModule::IncludeModule("extranet") && (CSocNetUser::IsCurrentUserModuleAdmin(SITE_ID, false) || $GLOBALS["APPLICATION"]->GetGroupRight("socialnetwork", false, "Y", "Y", array(CExtranet::GetExtranetSiteID(), false)) >= "K")) {
                 // check and create group, for extranet only
                 $dbSubjects = CSocNetGroupSubject::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("SITE_ID" => CExtranet::GetExtranetSiteID()), false, false, array("ID"));
                 if ($arSubject = $dbSubjects->GetNext()) {
                     $arSocNetGroupFields = array("NAME" => $arGroupName[$match[1]], "DESCRIPTION" => "", "VISIBLE" => "N", "OPENED" => "N", "CLOSED" => "N", "SUBJECT_ID" => $arSubject["ID"], "INITIATE_PERMS" => "E", "SPAM_PERMS" => "K", "SITE_ID" => array(SITE_ID, CExtranet::GetExtranetSiteID()));
                     if ($group_id = CSocNetGroup::CreateGroup($GLOBALS["USER"]->GetID(), $arSocNetGroupFields, false)) {
                         $arGroupToAdd[] = $group_id;
                     } elseif ($e = $GLOBALS["APPLICATION"]->GetException()) {
                         $strError = $e->GetString();
                     }
                 }
             } elseif (preg_match('/^SG(\\d+)$/', $group_code, $match)) {
                 $group_id = $match[1];
                 if (($arGroup = CSocNetGroup::GetByID($group_id)) && ($arCurrentUserPerms = CSocNetUserToGroup::InitUserPerms($GLOBALS["USER"]->GetID(), $arGroup, CSocNetUser::IsCurrentUserModuleAdmin(SITE_ID, false))) && $arCurrentUserPerms["UserCanInitiate"] && $arGroup["CLOSED"] != "Y") {
                     $arGroupToAdd[] = $group_id;
                 }
             }
         }
         if (!$strError) {
             $arAccessCodes = array();
             foreach ($arGroupToAdd as $group_id) {
                 foreach ($arUserId as $user_id) {
                     if (!CSocNetUserToGroup::SendRequestToJoinGroup($GLOBALS["USER"]->GetID(), $user_id, $group_id, "", false)) {
                         if ($e = $GLOBALS["APPLICATION"]->GetException()) {
                             $strError .= $e->GetString();
                         }
                     }
                 }
                 $arAccessCodes[] = 'SG' . $group_id;
             }
             if (!empty($arAccessCodes)) {
                 \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "USER_INVITE", "CODE" => $arAccessCodes));
             }
         }
     }
     return $strError;
 }
Exemplo n.º 9
0
 public static function migrateData()
 {
     $res = \CUserOptions::getList(array(), array("CATEGORY" => "socialnetwork", "NAME" => "log_destination"));
     while ($option = $res->fetch()) {
         if (!empty($option["VALUE"])) {
             $optionValue = unserialize($option["VALUE"]);
             if (is_array($optionValue)) {
                 foreach ($optionValue as $key => $val) {
                     if (in_array($key, array("users", "sonetgroups", "department", "companies", "contacts", "leads", "deals"))) {
                         $codes = \CUtil::jsObjectToPhp($val);
                         if (is_array($codes)) {
                             \Bitrix\Main\FinderDestTable::merge(array("USER_ID" => $option["USER_ID"], "CONTEXT" => "blog_post", "CODE" => array_keys($codes)));
                         }
                     }
                 }
             }
         }
     }
     $res = \CUserOptions::getList(array(), array("CATEGORY" => "crm", "NAME" => "log_destination"));
     while ($option = $res->fetch()) {
         if (!empty($option["VALUE"])) {
             $optionValue = unserialize($option["VALUE"]);
             if (is_array($optionValue)) {
                 foreach ($optionValue as $key => $val) {
                     $codes = explode(',', $val);
                     if (is_array($codes)) {
                         \Bitrix\Main\FinderDestTable::merge(array("USER_ID" => $option["USER_ID"], "CONTEXT" => "crm_post", "CODE" => $codes));
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 10
0
 public static function Request($action = '')
 {
     global $APPLICATION;
     if ($_REQUEST['skip_unescape'] !== 'Y') {
         CUtil::JSPostUnEscape();
     }
     // Export calendar
     if ($action == 'export') {
         // We don't need to check access  couse we will check security SIGN from the URL
         $sectId = intVal($_GET['sec_id']);
         if ($_GET['check'] == 'Y') {
             $APPLICATION->RestartBuffer();
             if (CCalendarSect::CheckSign($_GET['sign'], intVal($_GET['user']), $sectId > 0 ? $sectId : 'superposed_calendars')) {
                 echo 'BEGIN:VCALENDAR';
             }
             CMain::FinalActions();
             die;
         }
         if (CCalendarSect::CheckAuthHash() && $sectId > 0) {
             // We don't need any warning in .ics file
             error_reporting(E_COMPILE_ERROR | E_ERROR | E_CORE_ERROR | E_PARSE);
             CCalendarSect::ReturnICal(array('sectId' => $sectId, 'userId' => intVal($_GET['user']), 'sign' => $_GET['sign'], 'type' => $_GET['type'], 'ownerId' => intVal($_GET['owner'])));
         }
     } else {
         // // First of all - CHECK ACCESS
         if (!CCalendarType::CanDo('calendar_type_view', self::$type) || !check_bitrix_sessid()) {
             return $APPLICATION->ThrowException(GetMessage("EC_ACCESS_DENIED"));
         }
         $APPLICATION->ShowAjaxHead();
         $APPLICATION->RestartBuffer();
         $reqId = intVal($_REQUEST['reqId']);
         switch ($action) {
             // * * * * * Add and Edit event * * * * *
             case 'edit_event':
                 if (self::$bReadOnly || !CCalendarType::CanDo('calendar_type_view', self::$type)) {
                     return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                 }
                 $id = intVal($_POST['id']);
                 if (isset($_POST['section'])) {
                     $sectId = intVal($_POST['section']);
                     $_POST['sections'] = array($sectId);
                 } else {
                     $sectId = intVal($_POST['sections'][0]);
                 }
                 if (self::$type != 'user' || self::$ownerId != self::$userId) {
                     if (!$id && !CCalendarSect::CanDo('calendar_add', $sectId, self::$userId)) {
                         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                     }
                     if ($id && !CCalendarSect::CanDo('calendar_edit', $sectId, self::$userId)) {
                         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                     }
                 }
                 // Default name for events
                 $_POST['name'] = trim($_POST['name']);
                 if ($_POST['name'] == '') {
                     $_POST['name'] = GetMessage('EC_DEFAULT_EVENT_NAME');
                 }
                 $remind = array();
                 if (isset($_POST['remind']['checked']) && $_POST['remind']['checked'] == 'Y') {
                     $remind[] = array('type' => $_POST['remind']['type'], 'count' => intval($_POST['remind']['count']));
                 }
                 $rrule = isset($_POST['rrule_enabled']) ? $_POST['rrule'] : false;
                 // Date & Time
                 $dateFrom = $_POST['date_from'];
                 $dateTo = $_POST['date_to'];
                 $skipTime = isset($_POST['skip_time']) && $_POST['skip_time'] == 'Y';
                 if (!$skipTime) {
                     $dateFrom .= ' ' . $_POST['time_from'];
                     $dateTo .= ' ' . $_POST['time_to'];
                 }
                 // Timezone
                 $tzFrom = $_POST['tz_from'];
                 $tzTo = $_POST['tz_to'];
                 if (!$tzFrom && isset($_POST['default_tz'])) {
                     $tzFrom = $_POST['default_tz'];
                 }
                 if (!$tzTo && isset($_POST['default_tz'])) {
                     $tzTo = $_POST['default_tz'];
                 }
                 if (isset($_POST['default_tz']) && $_POST['default_tz'] != '') {
                     self::SaveUserTimezoneName(self::$userId, $_POST['default_tz']);
                 }
                 $arFields = array("ID" => $id, "DATE_FROM" => $dateFrom, "DATE_TO" => $dateTo, 'TZ_FROM' => $tzFrom, 'TZ_TO' => $tzTo, 'NAME' => $_POST['name'], 'DESCRIPTION' => trim($_POST['desc']), 'SECTIONS' => $_POST['sections'], 'COLOR' => $_POST['color'], 'TEXT_COLOR' => $_POST['text_color'], 'ACCESSIBILITY' => $_POST['accessibility'], 'IMPORTANCE' => $_POST['importance'], 'PRIVATE_EVENT' => $_POST['private_event'] == 'Y', 'RRULE' => $rrule, 'LOCATION' => is_array($_POST['location']) ? $_POST['location'] : array(), "REMIND" => $remind, "IS_MEETING" => !!$_POST['is_meeting'], "SKIP_TIME" => $skipTime);
                 $arAccessCodes = array();
                 if (isset($_POST['EVENT_DESTINATION'])) {
                     foreach ($_POST["EVENT_DESTINATION"] as $v => $k) {
                         if (strlen($v) > 0 && is_array($k) && !empty($k)) {
                             foreach ($k as $vv) {
                                 if (strlen($vv) > 0) {
                                     $arAccessCodes[] = $vv;
                                 }
                             }
                         }
                     }
                     if (!$arFields["ID"]) {
                         $arAccessCodes[] = 'U' . self::$userId;
                     }
                     $arAccessCodes = array_unique($arAccessCodes);
                 }
                 $arFields['IS_MEETING'] = !empty($arAccessCodes) && $arAccessCodes != array('U' . self::$userId);
                 if ($arFields['IS_MEETING']) {
                     $arFields['ATTENDEES_CODES'] = $arAccessCodes;
                     $arFields['ATTENDEES'] = CCalendar::GetDestinationUsers($arAccessCodes);
                     $arFields['MEETING_HOST'] = self::$userId;
                     $arFields['MEETING'] = array('HOST_NAME' => self::GetUserName($arFields['MEETING_HOST']), 'TEXT' => isset($_POST['meeting_text']) ? $_POST['meeting_text'] : '', 'OPEN' => $_POST['open_meeting'] === 'Y', 'NOTIFY' => $_POST['meeting_notify'] === 'Y', 'REINVITE' => $_POST['meeting_reinvite'] === 'Y');
                 }
                 // Userfields for event
                 $arUFFields = array();
                 foreach ($_POST as $field => $value) {
                     if (substr($field, 0, 3) == "UF_") {
                         $arUFFields[$field] = $value;
                     }
                 }
                 $newId = self::SaveEvent(array('arFields' => $arFields, 'UF' => $arUFFields));
                 if ($newId) {
                     $arFilter = array("ID" => $newId);
                     $month = intVal($_REQUEST['month']);
                     $year = intVal($_REQUEST['year']);
                     $arFilter["FROM_LIMIT"] = self::Date(mktime(0, 0, 0, $month - 1, 20, $year), false);
                     $arFilter["TO_LIMIT"] = self::Date(mktime(0, 0, 0, $month + 1, 10, $year), false);
                     $arAttendees = array();
                     // List of attendees for event
                     $arEvents = CCalendarEvent::GetList(array('arFilter' => $arFilter, 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => self::$userId));
                     if ($arFields['IS_MEETING']) {
                         \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "CALENDAR", "CODE" => \Bitrix\Main\FinderDestTable::convertRights($arAccessCodes, array('U' . self::$userId))));
                     }
                 }
                 if ($arEvents && $arFields['IS_MEETING']) {
                     $arAttendees = CCalendarEvent::GetLastAttendees();
                 }
                 CCalendar::OutputJSRes($reqId, array('id' => $newId, 'events' => $arEvents, 'attendees' => $arAttendees, 'deletedEventId' => $id && $newId != $id ? $id : 0));
                 break;
             case 'move_event_to_date':
                 if (self::$bReadOnly || !CCalendarType::CanDo('calendar_type_view', self::$type)) {
                     return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                 }
                 $id = intVal($_POST['id']);
                 $sectId = intVal($_POST['section']);
                 if (self::$type != 'user' || self::$ownerId != self::$userId) {
                     if (!$id && !CCalendarSect::CanDo('calendar_add', $sectId, self::$userId)) {
                         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                     }
                     if ($id && !CCalendarSect::CanDo('calendar_edit', $sectId, self::$userId)) {
                         return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                     }
                 }
                 $skipTime = isset($_POST['skip_time']) && $_POST['skip_time'] == 'Y';
                 $arFields = array("ID" => $id, "DATE_FROM" => CCalendar::Date(CCalendar::Timestamp($_POST['date_from']), !$skipTime), "SKIP_TIME" => $skipTime);
                 if (isset($_POST['date_to'])) {
                     $arFields["DATE_TO"] = CCalendar::Date(CCalendar::Timestamp($_POST['date_to']), !$skipTime);
                 }
                 if (!$skipTime && isset($_POST['timezone']) && $_POST['timezone']) {
                     $arFields["TZ_FROM"] = $_POST['timezone'];
                     $arFields["TZ_TO"] = $_POST['timezone'];
                 }
                 //SaveEvent
                 $id = self::SaveEvent(array('arFields' => $arFields));
                 CCalendar::OutputJSRes($reqId, array('id' => $id));
                 break;
                 // * * * * * Delete event * * * * *
             // * * * * * Delete event * * * * *
             case 'delete':
                 if (self::$bReadOnly || !CCalendarType::CanDo('calendar_type_view', self::$type)) {
                     return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                 }
                 $res = self::DeleteEvent(intVal($_POST['id']));
                 if ($res !== true) {
                     return CCalendar::ThrowError(strlen($res) > 0 ? $res : GetMessage('EC_EVENT_DEL_ERROR'));
                 }
                 CCalendar::OutputJSRes($reqId, true);
                 break;
                 // * * * * * Load events for some time limits * * * * *
             // * * * * * Load events for some time limits * * * * *
             case 'load_events':
                 $arSect = array();
                 $arHiddenSect = array();
                 $month = intVal($_REQUEST['month']);
                 $year = intVal($_REQUEST['year']);
                 $fromLimit = self::Date(mktime(0, 0, 0, $month - 1, 20, $year), false);
                 $toLimit = self::Date(mktime(0, 0, 0, $month + 1, 10, $year), false);
                 if ($_REQUEST['cal_dav_data_sync'] == 'Y' && CCalendar::IsCalDAVEnabled()) {
                     CDavGroupdavClientCalendar::DataSync("user", self::$ownerId);
                 }
                 $bGetTask = false;
                 if (is_array($_REQUEST['active_sect'])) {
                     foreach ($_REQUEST['active_sect'] as $sectId) {
                         if ($sectId == 'tasks') {
                             $bGetTask = true;
                         } elseif (intval($sectId) > 0) {
                             $arSect[] = intval($sectId);
                         }
                     }
                 }
                 if (is_array($_REQUEST['hidden_sect'])) {
                     foreach ($_REQUEST['hidden_sect'] as $sectId) {
                         if ($sectId == 'tasks') {
                             $arHiddenSect[] = 'tasks';
                         } elseif (intval($sectId) > 0) {
                             $arHiddenSect[] = intval($sectId);
                         }
                     }
                 }
                 $arAttendees = array();
                 // List of attendees for each event Array([ID] => Array(), ..,);
                 $arEvents = array();
                 if (count($arSect) > 0) {
                     // NOTICE: Attendees for meetings selected inside this method and returns as array by link '$arAttendees'
                     $arEvents = self::GetEventList(array('type' => self::$type, 'section' => $arSect, 'fromLimit' => $fromLimit, 'toLimit' => $toLimit), $arAttendees);
                 }
                 if (is_array($_REQUEST['sup_sect'])) {
                     $arDisplayedSPSections = array();
                     foreach ($_REQUEST['sup_sect'] as $sectId) {
                         $arDisplayedSPSections[] = intval($sectId);
                     }
                     if (count($arDisplayedSPSections) > 0) {
                         $arSuperposedEvents = CCalendarEvent::GetList(array('arFilter' => array("FROM_LIMIT" => $fromLimit, "TO_LIMIT" => $toLimit, "SECTION" => $arDisplayedSPSections), 'parseRecursion' => true, 'fetchAttendees' => true, 'userId' => self::$userId));
                         $arEvents = array_merge($arEvents, $arSuperposedEvents);
                     }
                 }
                 //  **** GET TASKS ****
                 $arTaskIds = array();
                 if (self::$bTasks && $bGetTask) {
                     $arTasks = self::GetTaskList(array('fromLimit' => $fromLimit, 'toLimit' => $toLimit), $arTaskIds);
                     if (count($arTasks) > 0) {
                         $arEvents = array_merge($arEvents, $arTasks);
                     }
                 }
                 // Save hidden calendars
                 CCalendarSect::Hidden(self::$userId, $arHiddenSect);
                 CCalendar::OutputJSRes($reqId, array('events' => $arEvents, 'attendees' => $arAttendees));
                 break;
                 // * * * * * Edit calendar * * * * *
             // * * * * * Edit calendar * * * * *
             case 'section_edit':
                 $id = intVal($_POST['id']);
                 $bNew = !isset($id) || $id == 0;
                 if ($bNew) {
                     if (self::$type == 'group') {
                         // It's for groups
                         if (!self::$perm['section_edit']) {
                             return CCalendar::ThrowError('[se01]' . GetMessage('EC_ACCESS_DENIED'));
                         }
                     } else {
                         if (self::$type == 'user') {
                             if (!self::IsPersonal()) {
                                 // If it's not owner of the group.
                                 return CCalendar::ThrowError('[se02]' . GetMessage('EC_ACCESS_DENIED'));
                             }
                         } else {
                             if (!CCalendarType::CanDo('calendar_type_edit_section', self::$type)) {
                                 return CCalendar::ThrowError('[se03]' . GetMessage('EC_ACCESS_DENIED'));
                             }
                         }
                     }
                 } elseif (!self::IsPersonal() && !$bNew && !CCalendarSect::CanDo('calendar_edit_section', $id, self::$userId)) {
                     return CCalendar::ThrowError(GetMessage('[se02]EC_ACCESS_DENIED'));
                 }
                 $arFields = array('CAL_TYPE' => self::$type, 'ID' => $id, 'NAME' => trim($_POST['name']), 'DESCRIPTION' => trim($_POST['desc']), 'COLOR' => $_POST['color'], 'TEXT_COLOR' => $_POST['text_color'], 'OWNER_ID' => self::$bOwner ? self::GetOwnerId() : '', 'EXPORT' => array('ALLOW' => isset($_POST['export']) && $_POST['export'] == 'Y', 'SET' => $_POST['exp_set']), 'ACCESS' => is_array($_POST['access']) ? $_POST['access'] : array());
                 if ($bNew) {
                     $arFields['IS_EXCHANGE'] = $_POST['is_exchange'] == 'Y';
                 }
                 $id = intVal(self::SaveSection(array('arFields' => $arFields)));
                 if ($id > 0) {
                     CCalendarSect::SetClearOperationCache(true);
                     $oSect = CCalendarSect::GetById($id, true, true);
                     if (!$oSect) {
                         return CCalendar::ThrowError(GetMessage('EC_CALENDAR_SAVE_ERROR'));
                     }
                     if (self::$type == 'user' && isset($_POST['is_def_meet_calendar']) && $_POST['is_def_meet_calendar'] == 'Y') {
                         $set = CCalendar::GetUserSettings(self::$ownerId);
                         $set['meetSection'] = $id;
                         CCalendar::SetUserSettings($set, self::$ownerId);
                     }
                     CCalendar::OutputJSRes($reqId, array('calendar' => $oSect, 'accessNames' => CCalendar::GetAccessNames()));
                 }
                 if ($id <= 0) {
                     return CCalendar::ThrowError(GetMessage('EC_CALENDAR_SAVE_ERROR'));
                 }
                 break;
                 // * * * * * Delete calendar * * * * *
             // * * * * * Delete calendar * * * * *
             case 'section_delete':
                 $sectId = intVal($_REQUEST['id']);
                 if (!self::IsPersonal() && !CCalendarSect::CanDo('calendar_edit_section', $sectId, self::$userId)) {
                     return CCalendar::ThrowError(GetMessage('EC_ACCESS_DENIED'));
                 }
                 $res = self::DeleteSection($sectId);
                 // if ($res !== true)
                 // return CCalendar::ThrowError(strlen($res) > 0 ? $res : GetMessage('EC_CALENDAR_DEL_ERROR'));
                 CCalendar::OutputJSRes($reqId, array('result' => true));
                 break;
                 // * * * * * Save superposed sections * * * * *
             // * * * * * Save superposed sections * * * * *
             case 'set_superposed':
                 $trackedUser = intVal($_REQUEST['trackedUser']);
                 if ($trackedUser > 0) {
                     $arUserIds = self::TrackingUsers(self::$userId);
                     if (!in_array($trackedUser, $arUserIds)) {
                         $arUserIds[] = $trackedUser;
                         self::TrackingUsers(self::$userId, $arUserIds);
                     }
                 }
                 if (CCalendar::SetDisplayedSuperposed(self::$userId, $_REQUEST['sect'])) {
                     CCalendar::OutputJSRes($reqId, array('result' => true));
                 } else {
                     CCalendar::ThrowError('Error! Cant save displayed superposed calendars');
                 }
                 break;
                 // * * * * * Fetch all available sections for superposing * * * * *
             // * * * * * Fetch all available sections for superposing * * * * *
             case 'get_superposed':
                 CCalendar::OutputJSRes($reqId, array('sections' => CCalendar::GetSuperposed()));
                 break;
                 // * * * * * Return info about user, and user calendars * * * * *
             // * * * * * Return info about user, and user calendars * * * * *
             case 'spcal_user_cals':
                 CCalendar::OutputJSRes($reqId, array('sections' => CCalendar::GetSuperposedForUsers($_REQUEST['users'])));
                 break;
                 // * * * * * Delete tracking user * * * * *
             // * * * * * Delete tracking user * * * * *
             case 'spcal_del_user':
                 CCalendar::OutputJSRes($reqId, array('result' => CCalendar::DeleteTrackingUser(intVal($_REQUEST['userId']))));
                 break;
                 // * * * * * Save user settings * * * * *
             // * * * * * Save user settings * * * * *
             case 'save_settings':
                 if (isset($_POST['clear_all']) && $_POST['clear_all'] == true) {
                     // Clear personal settings
                     CCalendar::SetUserSettings(false);
                 } else {
                     // Personal
                     CCalendar::SetUserSettings($_REQUEST['user_settings']);
                     // Save access for type
                     if (CCalendarType::CanDo('calendar_type_access', self::$type)) {
                         // General
                         $_REQUEST['settings']['week_holidays'] = implode('|', $_REQUEST['settings']['week_holidays']);
                         CCalendar::SetSettings($_REQUEST['settings']);
                         CCalendarType::Edit(array('arFields' => array('XML_ID' => self::$type, 'ACCESS' => $_REQUEST['type_access'])));
                     }
                 }
                 if (isset($_POST['user_timezone_name'])) {
                     self::SaveUserTimezoneName(self::$userId, $_POST['user_timezone_name']);
                 }
                 CCalendar::OutputJSRes($reqId, array('result' => true));
                 break;
                 // * * * * * Confirm user part in event * * * * *
             // * * * * * Confirm user part in event * * * * *
             case 'set_meeting_status':
                 CCalendarEvent::SetMeetingStatus(self::$userId, intVal($_REQUEST['event_id']), in_array($_REQUEST['status'], array('Q', 'Y', 'N')) ? $_REQUEST['status'] : 'Q', $_REQUEST['status_comment']);
                 CCalendar::OutputJSRes($reqId, true);
                 break;
             case 'set_meeting_params':
                 CCalendarEvent::SetMeetingParams(self::$userId, intVal($_REQUEST['event_id']), array('ACCESSIBILITY' => $_REQUEST['accessibility'], 'REMIND' => $_REQUEST['remind']));
                 CCalendar::OutputJSRes($reqId, true);
                 break;
                 // * * * * * Get list of group members * * * * *
             // * * * * * Get list of group members * * * * *
             case 'get_group_members':
                 if (self::$type == 'group') {
                     CCalendar::OutputJSRes($reqId, array('users' => self::GetGroupMembers(self::$ownerId)));
                 }
                 break;
                 // * * * * * Get Guests Accessibility * * * * *
             // * * * * * Get Guests Accessibility * * * * *
             case 'get_accessibility':
                 $res = CCalendar::GetAccessibilityForUsers(array('users' => $_POST['users'], 'from' => self::Date(self::Timestamp($_POST['from'])), 'to' => self::Date(self::Timestamp($_POST['to'])), 'curEventId' => intVal($_POST['cur_event_id']), 'getFromHR' => true));
                 CCalendar::OutputJSRes($reqId, array('data' => $res));
                 break;
                 // * * * * * Get meeting room accessibility * * * * *
             // * * * * * Get meeting room accessibility * * * * *
             case 'get_mr_accessibility':
                 $res = CCalendar::GetAccessibilityForMeetingRoom(array('id' => intVal($_POST['id']), 'from' => self::Date(self::Timestamp($_POST['from'])), 'to' => self::Date(self::Timestamp($_POST['to'])), 'curEventId' => intVal($_POST['cur_event_id'])));
                 CCalendar::OutputJSRes($reqId, array('data' => $res));
                 break;
                 // * * * * * Get meeting room accessibility * * * * *
             // * * * * * Get meeting room accessibility * * * * *
             case 'check_meeting_room':
                 $check = false;
                 if (self::$allowReserveMeeting || self::$allowVideoMeeting) {
                     $from = self::Date(self::Timestamp($_POST['from']));
                     $to = self::Date(self::Timestamp($_POST['to']));
                     $loc_old = $_POST['location_old'] ? CCalendar::ParseLocation(trim($_POST['location_old'])) : false;
                     $loc_new = CCalendar::ParseLocation(trim($_POST['location_new']));
                     $Params = array('dateFrom' => $from, 'dateTo' => $to, 'regularity' => 'NONE', 'members' => isset($_POST['guest']) ? $_POST['guest'] : false);
                     //						$tst = MakeTimeStamp($Params['dateTo']);
                     //						if (date("H:i", $tst) == '00:00')
                     //							$Params['dateTo'] = CIBlockFormatProperties::DateFormat(self::DFormat(true), $tst + (23 * 60 + 59) * 60);
                     if (intVal($_POST['id']) > 0) {
                         $Params['ID'] = intVal($_POST['id']);
                     }
                     if (self::$allowVideoMeeting && $loc_new['mrid'] == self::$settings['vr_iblock_id']) {
                         $Params['VMiblockId'] = self::$settings['vr_iblock_id'];
                         if ($loc_old['mrevid'] > 0) {
                             $Params['ID'] = $loc_old['mrevid'];
                         }
                         $check = CCalendar::CheckVideoRoom($Params);
                     } elseif (self::$allowReserveMeeting) {
                         $Params['RMiblockId'] = self::$settings['rm_iblock_id'];
                         $Params['mrid'] = $loc_new['mrid'];
                         $Params['mrevid_old'] = $loc_old ? $loc_old['mrevid'] : 0;
                         $check = CCalendar::CheckMeetingRoom($Params);
                     }
                 }
                 CCalendar::OutputJSRes($reqId, array('check' => $check));
                 break;
             case 'connections_edit':
                 if (self::$type == 'user' && CCalendar::IsCalDAVEnabled()) {
                     $res = CCalendar::ManageConnections($_POST['connections']);
                     if ($res !== true) {
                         CCalendar::ThrowError($res == '' ? 'Edit connections error' : $res);
                     } else {
                         CCalendar::OutputJSRes($reqId, array('result' => true));
                     }
                 }
                 break;
             case 'exchange_sync':
                 if (self::$type == 'user' && CCalendar::IsExchangeEnabled(self::$ownerId)) {
                     $error = "";
                     $res = CDavExchangeCalendar::DoDataSync(self::$ownerId, $error);
                     if ($res === true || $res === false) {
                         CCalendar::OutputJSRes($reqId, array('result' => true));
                     } else {
                         CCalendar::ThrowError($error);
                     }
                 }
                 break;
             case 'get_view_event_dialog':
                 $APPLICATION->ShowAjaxHead();
                 $jsId = $color = preg_replace('/[^\\d|\\w]/', '', $_REQUEST['js_id']);
                 $eventId = intval($_REQUEST['event_id']);
                 $fromTs = CCalendar::Timestamp($_REQUEST['date_from']);
                 $Event = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "DELETED" => "N", "FROM_LIMIT" => CCalendar::Date($fromTs - 3600), "TO_LIMIT" => CCalendar::Date($fromTs + CCalendar::GetDayLen(), false, false)), 'parseRecursion' => true, 'maxInstanceCount' => 1, 'preciseLimits' => true, 'fetchAttendees' => true, 'checkPermissions' => true, 'setDefaultLimit' => false));
                 if (!$Event || !is_array($Event[0])) {
                     $Event = CCalendarEvent::GetList(array('arFilter' => array("ID" => $eventId, "DELETED" => "N"), 'parseRecursion' => true, 'maxInstanceCount' => 1, 'fetchAttendees' => true, 'checkPermissions' => true, 'setDefaultLimit' => false));
                 }
                 if ($Event && is_array($Event[0])) {
                     CCalendarSceleton::DialogViewEvent(array('id' => $jsId, 'event' => $Event[0], 'sectionName' => $_REQUEST['section_name'], 'bIntranet' => self::IsIntranetEnabled(), 'bSocNet' => self::IsSocNet(), 'AVATAR_SIZE' => 21));
                 }
                 require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog_after.php";
                 break;
             case 'get_edit_event_dialog':
                 $APPLICATION->ShowAjaxHead();
                 $jsId = $color = preg_replace('/[^\\d|\\w]/', '', $_REQUEST['js_id']);
                 $event_id = intval($_REQUEST['event_id']);
                 if ($event_id > 0) {
                     $Event = CCalendarEvent::GetList(array('arFilter' => array("ID" => $event_id), 'parseRecursion' => false, 'fetchAttendees' => true, 'checkPermissions' => true, 'setDefaultLimit' => false));
                     $Event = $Event && is_array($Event[0]) ? $Event[0] : false;
                 } else {
                     $Event = array();
                 }
                 if (!$event_id || !empty($Event)) {
                     CCalendarSceleton::DialogEditEvent(array('id' => $jsId, 'event' => $Event, 'type' => self::$type, 'bIntranet' => self::IsIntranetEnabled(), 'bSocNet' => self::IsSocNet(), 'AVATAR_SIZE' => 21));
                 }
                 require $_SERVER["DOCUMENT_ROOT"] . BX_ROOT . "/modules/main/include/epilog_after.php";
                 break;
             case 'get_attendees_by_codes_planner':
             case 'get_attendees_by_codes':
                 $bPlanner = $action == 'get_attendees_by_codes_planner';
                 $users = CCalendar::GetDestinationUsers($_REQUEST['codes'], true);
                 $userIds = array();
                 $result = array();
                 foreach ($users as $user) {
                     $userIds[] = $user['USER_ID'];
                     $result[] = array('USER_ID' => $user['USER_ID'], 'DISPLAY_NAME' => CCalendar::GetUserName($user), 'AVATAR' => CCalendar::GetUserAvatarSrc($user), 'ACC' => '', 'URL' => CCalendar::GetUserUrl($user['USER_ID'], self::$pathToUser));
                 }
                 //					if ($_REQUEST['event_from_ts'] && $_REQUEST['event_to_ts'])
                 //					{
                 //						$acc = CCalendar::CheckUsersAccessibility(array(
                 //							'users' => $userIds,
                 //							'from' => self::Date(self::_fixTimestamp($_REQUEST['event_from_ts'])),
                 //							'to' => self::Date(self::_fixTimestamp($_REQUEST['event_to_ts'])),
                 //							'eventId' => intVal($_REQUEST['cur_event_id'])
                 //						));
                 //						foreach($result as $i => $user)
                 //							$result[$i]['ACC'] = $acc[$user['USER_ID']];
                 //					}
                 //$skipTime = $_REQUEST['skip_time'] == 'Y';
                 //					$fromTs = self::Timestamp($_REQUEST['date_from']);
                 //					$toTs = self::Timestamp($_REQUEST['date_to']);
                 $from = self::Date(self::Timestamp($_REQUEST['date_from']), false);
                 $to = self::Date(self::Timestamp($_REQUEST['date_to']), false);
                 $accessibility = CCalendar::GetAccessibilityForUsers(array('users' => $userIds, 'from' => $from, 'to' => $to, 'curEventId' => intVal($_REQUEST['cur_event_id']), 'getFromHR' => true));
                 CCalendar::OutputJSRes($reqId, array('users' => $result, 'accessibility' => $accessibility));
                 break;
         }
     }
     if ($ex = $APPLICATION->GetException()) {
         ShowError($ex->GetString());
     }
     CMain::FinalActions();
     die;
 }