Пример #1
0
 protected static function SaveCalendarEvent(&$arFields)
 {
     $responsibleID = isset($arFields['RESPONSIBLE_ID']) ? intval($arFields['RESPONSIBLE_ID']) : 0;
     $typeID = isset($arFields['TYPE_ID']) ? intval($arFields['TYPE_ID']) : CCrmActivityType::Undefined;
     if (!($responsibleID > 0 && ($typeID === CCrmActivityType::Call || $typeID === CCrmActivityType::Meeting))) {
         return false;
     }
     if (!(IsModuleInstalled('calendar') && CModule::IncludeModule('calendar'))) {
         return false;
     }
     $arCalEventFields = array('CAL_TYPE' => 'user', 'OWNER_ID' => $responsibleID, 'NAME' => isset($arFields['SUBJECT']) ? $arFields['SUBJECT'] : '', 'DT_FROM' => isset($arFields['START_TIME']) ? $arFields['START_TIME'] : '', 'DT_TO' => isset($arFields['END_TIME']) ? $arFields['END_TIME'] : '', 'IMPORTANCE' => CCrmActivityPriority::ToCalendarEventImportance(isset($arFields['PRIORITY']) ? intval($arFields['PRIORITY']) : CCrmActivityPriority::Low), 'DESCRIPTION' => isset($arFields['DESCRIPTION']) ? $arFields['DESCRIPTION'] : '');
     $associatedEntityID = isset($arFields['ASSOCIATED_ENTITY_ID']) ? intval($arFields['ASSOCIATED_ENTITY_ID']) : 0;
     if ($associatedEntityID > 0) {
         $arCalEventFields['ID'] = $associatedEntityID;
         $arPresentEventFields = CCalendarEvent::GetById($associatedEntityID, false);
         if (is_array($arPresentEventFields)) {
             if (isset($arPresentEventFields['RRULE']) && $arPresentEventFields['RRULE'] != '') {
                 $arCalEventFields['RRULE'] = CCalendarEvent::ParseRRULE($arPresentEventFields['RRULE']);
             }
             if (isset($arPresentEventFields['DT_LENGTH'])) {
                 $arCalEventFields['DT_LENGTH'] = $arPresentEventFields['DT_LENGTH'];
             }
         }
     }
     if (isset($arFields['NOTIFY_TYPE']) && $arFields['NOTIFY_TYPE'] != CCrmActivityNotifyType::None) {
         $arCalEventFields['REMIND'] = array(array('type' => CCrmActivityNotifyType::ToCalendarEventRemind($arFields['NOTIFY_TYPE']), 'count' => isset($arFields['NOTIFY_VALUE']) ? intval($arFields['NOTIFY_VALUE']) : 15));
     }
     self::$IGNORE_CALENDAR_EVENTS = true;
     // We must initialize CCalendar!
     $calendar = new CCalendar();
     $calendar->Init(array('type' => 'user', 'userId' => $responsibleID, 'ownerId' => $responsibleID));
     $result = $calendar->SaveEvent(array('arFields' => $arCalEventFields, 'userId' => $responsibleID, 'autoDetectSection' => true, 'autoCreateSection' => true));
     $eventID = intval($result);
     $ownerID = intval($arFields['OWNER_ID']);
     $ownerTypeID = intval($arFields['OWNER_TYPE_ID']);
     $arBindings = isset($arFields['BINDINGS']) ? $arFields['BINDINGS'] : array();
     if (empty($arBindings) && $ownerID > 0 && $ownerTypeID > 0) {
         $arBindings[] = array('OWNER_TYPE_ID' => $ownerTypeID, 'OWNER_ID' => $ownerID);
     }
     if ($eventID > 0 && !empty($arBindings)) {
         $arUserFields = array();
         foreach ($arBindings as &$arBinding) {
             $arUserFields[] = CUserTypeCrm::GetShortEntityType(CCrmOwnerType::ResolveName($arBinding['OWNER_TYPE_ID'])) . '_' . $arBinding['OWNER_ID'];
         }
         unset($arBinding);
         CCalendarEvent::UpdateUserFields($eventID, array('UF_CRM_CAL_EVENT' => $arUserFields));
     }
     self::$IGNORE_CALENDAR_EVENTS = false;
     return $result;
 }
Пример #2
0
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (!CModule::IncludeModule("calendar")) {
    return ShowError("EC_CALENDAR_MODULE_NOT_INSTALLED");
}
CModule::IncludeModule("socialnetwork");
$APPLICATION->ResetException();
$Params = array('type' => $arParams["CALENDAR_TYPE"], 'ownerId' => $arParams["OWNER_ID"], 'pageUrl' => htmlspecialcharsback(POST_FORM_ACTION_URI), 'allowSuperpose' => $arParams["ALLOW_SUPERPOSE"] == 'Y', 'allowResMeeting' => $arParams["ALLOW_RES_MEETING"] != 'N', 'allowVideoMeeting' => $arParams["ALLOW_RES_MEETING"] != 'N', 'SectionControlsDOMId' => 'sidebar', 'user_name_template' => empty($arParams['NAME_TEMPLATE']) ? CSite::GetNameFormat(false) : str_replace(array("#NOBR#", "#/NOBR#"), array("", ""), $arParams["NAME_TEMPLATE"]));
if (isset($arParams["SIDEBAR_DOM_ID"])) {
    $Params['SectionControlsDOMId'] = $arParams["SIDEBAR_DOM_ID"];
}
// Create new instance of Event Calendar object
$EC = new CCalendar();
$EC->Init($Params);
// Init with $Params array
if (isset($_REQUEST['action'])) {
    $EC->Request($_REQUEST['action']);
} else {
    $EC->Show();
}
if ($ex = $APPLICATION->GetException()) {
    return ShowError($ex->GetString());
}
// Set title and navigation
$arParams["SET_TITLE"] = $arParams["SET_TITLE"] == "Y" ? "Y" : "N";
$arParams["SET_NAV_CHAIN"] = $arParams["SET_NAV_CHAIN"] == "Y" ? "Y" : "N";
//Turn OFF by default
if ($arParams["STR_TITLE"]) {
    $arParams["STR_TITLE"] = trim($arParams["STR_TITLE"]);