public static function DoDeleteCalendar($userId, $itemXmlId) { if (DAV_EXCH_DEBUG) { CDav::WriteToLog("EXCHANGE DoDeleteCalendar called for user " . $userId, "MDFE"); } $exchangeScheme = COption::GetOptionString("dav", "exchange_scheme", "http"); $exchangeServer = COption::GetOptionString("dav", "exchange_server", ""); $exchangePort = COption::GetOptionString("dav", "exchange_port", "80"); $exchangeUsername = COption::GetOptionString("dav", "exchange_username", ""); $exchangePassword = COption::GetOptionString("dav", "exchange_password", ""); if (empty($exchangeServer)) { return ""; } $exchange = new CDavExchangeCalendar($exchangeScheme, $exchangeServer, $exchangePort, $exchangeUsername, $exchangePassword); if (GW_DEBUG) { $exchange->Debug(); } $exchangeMailbox = COption::GetOptionString("dav", "exchange_mailbox", ""); $exchangeUseLogin = COption::GetOptionString("dav", "exchange_use_login", "Y"); self::InitUserEntity(); if ($itemXmlId == "calendar_" . $userId) { return ''; } $userId = intval($userId); $dbUserList = CUser::GetList($by = "", $order = "", array("ACTIVE" => "Y", "!UF_DEPARTMENT" => false, "ID_EQUAL_EXACT" => $userId), array("SELECT" => array("ID", "LOGIN", "UF_BXDAVEX_MAILBOX", "UF_BXDAVEX_CALSYNC"))); if ($arUser = $dbUserList->Fetch()) { $mailbox = $exchangeUseLogin == "Y" ? $arUser["LOGIN"] . $exchangeMailbox : $arUser["UF_BXDAVEX_MAILBOX"]; if (!empty($mailbox)) { $arResult = $exchange->DeleteCalendar($itemXmlId); if ($arResult) { return $arResult; } } } return $exchange->GetErrors(); }
public static function DoDeleteItem($connectionId, $calendarXmlId, $itemXmlId) { if (DAV_CALDAV_DEBUG) { CDav::WriteToLog("CalDAV DoDeleteItem called for connection " . $connectionId, "MDFC"); } $connectionId = intval($connectionId); if ($connectionId <= 0) { return null; } $arConnection = CDavConnection::GetById($connectionId); if (!is_array($arConnection)) { return null; } $client = new CDavGroupdavClientCalendar($arConnection["SERVER_SCHEME"], $arConnection["SERVER_HOST"], $arConnection["SERVER_PORT"], $arConnection["SERVER_USERNAME"], $arConnection["SERVER_PASSWORD"]); if (CDav::UseProxy()) { $arProxy = CDav::GetProxySettings(); $client->SetProxy($arProxy["PROXY_SCHEME"], $arProxy["PROXY_HOST"], $arProxy["PROXY_PORT"], $arProxy["PROXY_USERNAME"], $arProxy["PROXY_PASSWORD"]); } //$client->Debug(); self::InitUserEntity(); $result = $client->DeleteCalendarItem($calendarXmlId . $itemXmlId . ".ics"); if ($result === true) { return $result; } return $client->GetErrors(); }
public static function DataSync($paramUserId = 0) { $exchangeScheme = COption::GetOptionString("dav", "exchange_scheme", "http"); $exchangeServer = COption::GetOptionString("dav", "exchange_server", ""); $exchangePort = COption::GetOptionString("dav", "exchange_port", "80"); $exchangeUsername = COption::GetOptionString("dav", "exchange_username", ""); $exchangePassword = COption::GetOptionString("dav", "exchange_password", ""); if (empty($exchangeServer)) { CAgent::RemoveAgent("CDavExchangeTasks::DataSync();", "dav"); COption::SetOptionString("dav", "agent_tasks", "N"); return ""; } $exchange = new CDavExchangeTasks($exchangeScheme, $exchangeServer, $exchangePort, $exchangeUsername, $exchangePassword); $exchangeMailbox = COption::GetOptionString("dav", "exchange_mailbox", ""); $exchangeUseLogin = COption::GetOptionString("dav", "exchange_use_login", "Y"); self::InitUserEntity(); $maxNumber = 5; $index = 0; $paramUserId = intval($paramUserId); $arUserFilter = array("ACTIVE" => "Y", "!UF_DEPARTMENT" => false); if ($paramUserId > 0) { $arUserFilter["ID_EQUAL_EXACT"] = $paramUserId; } if ($exchangeUseLogin == "N") { $arUserFilter["!UF_BXDAVEX_MAILBOX"] = false; } $arAdditionalExtendedProperties = array(array('DistinguishedPropertySetId' => 'PublicStrings', 'PropertyName' => 'BX_TASKS_GUID', 'PropertyType' => 'String'), array('DistinguishedPropertySetId' => 'PublicStrings', 'PropertyName' => 'BX_TASKS_SERIALIZED_DATA', 'PropertyType' => 'String')); $dbUserList = CUser::GetList($by = "UF_BXDAVEX_TSKSYNC", $order = "asc", $arUserFilter, array("SELECT" => array("ID", "LOGIN", "UF_BXDAVEX_MAILBOX", "UF_BXDAVEX_TSKSYNC"))); while ($arUser = $dbUserList->Fetch()) { $index++; if ($index > $maxNumber) { break; } $GLOBALS["USER_FIELD_MANAGER"]->Update("USER", $arUser["ID"], array("UF_BXDAVEX_TSKSYNC" => ConvertTimeStamp(time(), FULL))); $mailbox = $exchangeUseLogin == "Y" ? $arUser["LOGIN"] . $exchangeMailbox : $arUser["UF_BXDAVEX_MAILBOX"]; if (empty($mailbox)) { continue; } $arFoldersList = $exchange->GetFoldersList(array("mailbox" => $mailbox)); if (!is_array($arFoldersList)) { if (DAV_CALDAV_DEBUG) { CDav::WriteToLog('Error during tasks exchange: $exchange->GetFoldersList() returns unexpected result', ''); } return; } $arUserFolders = array("tasks" => GetMessage("DAV_EC_TASKS")); foreach ($arFoldersList as $value) { $arUserFolders[$value["XML_ID"]] = $value["NAME"]; } $arUserTaskItems = array(); $arUserTaskItemsFolder = array(); foreach ($arUserFolders as $userFolderXmlId => $userFolder) { $arTaskItemsList = $exchange->GetList(array("mailbox" => $mailbox, "FolderId" => $userFolderXmlId), array("ItemShape" => "IdOnly"), $arAdditionalExtendedProperties); if (!is_array($arTaskItemsList)) { if (DAV_CALDAV_DEBUG) { CDav::WriteToLog('Error during tasks exchange: $exchange->GetList() returns unexpected result', ''); } return; } foreach ($arTaskItemsList as $value) { $arUserTaskItems[] = array("XML_ID" => $value["XML_ID"], "MODIFICATION_LABEL" => $value["MODIFICATION_LABEL"]); $arUserTaskItemsFolder[$value["XML_ID"]] = $userFolderXmlId; } } $arModifiedUserTaskItems = CTaskSync::SyncTaskItems("exchange", $arUser["ID"], $arUserTaskItems); foreach ($arModifiedUserTaskItems as $value) { $arModifiedTaskItem = $exchange->GetById($value["XML_ID"], $arAdditionalExtendedProperties); if (is_array($arModifiedTaskItem) && count($arModifiedTaskItem) > 0) { $arModifiedTaskItem = $arModifiedTaskItem[0]; $arModifyEventArray = array_merge($arModifiedTaskItem, array("ID" => $value["ID"], "USER_ID" => $arUser["ID"], "FOLDER_ID" => $arUserFolders[$arUserTaskItemsFolder[$arModifiedTaskItem["XML_ID"]]])); //XML_ID, MODIFICATION_LABEL, SUBJECT, BODY, BODY_TYPE, DATE_CREATE, IMPORTANCE, REMINDER_MINUTES_BEFORE_START, ACTUAL_WORK, BILLING_INFORMATION, MILEAGE, START_DATE, DUE_DATE, IS_COMPLETE, IS_RECURRING, PERCENT_COMPLETE, STATUS, STATUS_DESCRIPTION, TOTAL_WORK, OWNER, RECURRING_TYPE, RECURRING_INTERVAL, RECURRING_DAYOFMONTH, RECURRING_DAYSOFWEEK, RECURRING_DAYOFWEEKINDEX, RECURRING_MONTH, RECURRING_STARTDATE, RECURRING_NUMBEROFOCCURRENCES, RECURRING_ENDDATE CTaskSync::SyncModifyTaskItem($arModifyEventArray); } } } return "CDavExchangeTasks::DataSync();"; }
public static function DataSync($paramUserId = 0) { if (DAV_EXCH_DEBUG) { CDav::WriteToLog("Starting EXCHANGE contacts sync...", "SC"); } $exchangeScheme = COption::GetOptionString("dav", "exchange_scheme", "http"); $exchangeServer = COption::GetOptionString("dav", "exchange_server", ""); $exchangePort = COption::GetOptionString("dav", "exchange_port", "80"); $exchangeUsername = COption::GetOptionString("dav", "exchange_username", ""); $exchangePassword = COption::GetOptionString("dav", "exchange_password", ""); if (empty($exchangeServer)) { CAgent::RemoveAgent("CDavExchangeContacts::DataSync();", "dav"); COption::SetOptionString("dav", "agent_contacts", "N"); return ""; } $exchange = new CDavExchangeContacts($exchangeScheme, $exchangeServer, $exchangePort, $exchangeUsername, $exchangePassword); if (GW_DEBUG) { $exchange->Debug(); } $exchangeMailbox = COption::GetOptionString("dav", "exchange_mailbox", ""); $exchangeUseLogin = COption::GetOptionString("dav", "exchange_use_login", "Y"); self::InitUserEntity(); $maxNumber = 5; $index = 0; $rootStructureName = null; $paramUserId = intval($paramUserId); $arUserFilter = array("ACTIVE" => "Y", "!UF_DEPARTMENT" => false); if ($paramUserId > 0) { $arUserFilter["ID_EQUAL_EXACT"] = $paramUserId; } if ($exchangeUseLogin == "N") { $arUserFilter["!UF_BXDAVEX_MAILBOX"] = false; } $dbUserList = CUser::GetList($by = "UF_BXDAVEX_CNTSYNC", $order = "asc", $arUserFilter, array("SELECT" => array("ID", "LOGIN", "UF_BXDAVEX_MAILBOX", "UF_BXDAVEX_CNTSYNC"))); while ($arUser = $dbUserList->Fetch()) { $index++; if ($index > $maxNumber) { break; } if (DAV_EXCH_DEBUG) { CDav::WriteToLog("Processing user [" . $arUser["ID"] . "] " . $arUser["LOGIN"], "SC"); } $lastSyncDate = $arUser["UF_BXDAVEX_CNTSYNC"]; if (empty($lastSyncDate)) { $lastSyncDate = ConvertTimeStamp(mktime(0, 0, 0, 1, 1, 2000), FULL); } $GLOBALS["USER_FIELD_MANAGER"]->Update("USER", $arUser["ID"], array("UF_BXDAVEX_CNTSYNC" => ConvertTimeStamp(time(), FULL))); $mailbox = $exchangeUseLogin == "Y" ? $arUser["LOGIN"] . $exchangeMailbox : $arUser["UF_BXDAVEX_MAILBOX"]; if (empty($mailbox)) { continue; } $tmpNumItems = 0; $arAddressbookCache = null; $dbUserListTmp = CUser::GetList($by = "ID", $order = "asc", array("TIMESTAMP_X_1" => $lastSyncDate, "ACTIVE" => "Y", "!UF_DEPARTMENT" => false)); if ($arUserTmp = $dbUserListTmp->Fetch()) { if (is_null($rootStructureName)) { $iblockStructure = COption::GetOptionInt("intranet", 'iblock_structure', 0); $db = CIBlockSection::GetList(array("LEFT_MARGIN" => "ASC"), array("IBLOCK_ID" => $iblockStructure)); if ($ar = $db->Fetch()) { $rootStructureName = $ar["NAME"]; } } if (is_null($rootStructureName)) { if (DAV_EXCH_DEBUG) { CDav::WriteToLog("ERROR: Root structure is not found", "SC"); } break; } $arAddressbooksList = $exchange->GetAddressbooksList(array("mailbox" => $mailbox)); $arErrorsTmp = $exchange->GetErrors(); if (count($arErrorsTmp) > 0) { $txt = ''; foreach ($arErrorsTmp as $v) { if (!empty($txt)) { $txt .= ", "; } $txt .= "[" . $v[0] . "] " . $v[1]; } if (DAV_EXCH_DEBUG) { CDav::WriteToLog("ERROR: " . $txt, "SC"); } continue; } $arAddressbook = null; foreach ($arAddressbooksList as $value) { if ($value["NAME"] == $rootStructureName) { $arAddressbook = $value; break; } } if (is_null($arAddressbook)) { $arAddressbook = $exchange->AddAddressbook(array("mailbox" => $mailbox, "NAME" => $rootStructureName)); } if (!is_array($arAddressbook) || !isset($arAddressbook["XML_ID"])) { if (DAV_EXCH_DEBUG) { CDav::WriteToLog("ERROR: Addressbook '" . $rootStructureName . "' for mailbox '" . $mailbox . "' is not found", "SC"); } continue; } if (is_null($arAddressbookCache)) { $arAddressbookCache = array(); $arPrs = $exchange->GetList(array("Mailbox" => $mailbox, "AddressbookId" => $arAddressbook["XML_ID"]), array("ItemShape" => "IdOnly", "AdditionalProperties" => array("contacts:GivenName", "contacts:MiddleName", "contacts:Surname"))); foreach ($arPrs as $prs) { $s = $prs["NAME"] . "/" . $prs["SECOND_NAME"] . "/" . $prs["LAST_NAME"]; $arAddressbookCache[$s] = array("XML_ID" => $prs["XML_ID"], "MODIFICATION_LABEL" => $prs["MODIFICATION_LABEL"]); } } do { $s = $arUserTmp["NAME"] . "/" . $arUserTmp["SECOND_NAME"] . "/" . $arUserTmp["LAST_NAME"]; if (array_key_exists($s, $arAddressbookCache)) { $exchange->Update($arAddressbookCache[$s], array_merge($arUserTmp, array("Mailbox" => $mailbox, "AddressbookId" => $arAddressbook["XML_ID"]))); } else { $exchange->Add(array_merge($arUserTmp, array("Mailbox" => $mailbox, "AddressbookId" => $arAddressbook["XML_ID"]))); } $arErrorsTmp = $exchange->GetErrors(); if (count($arErrorsTmp) > 0) { $txt = ''; foreach ($arErrorsTmp as $v) { if (!empty($txt)) { $txt .= ", "; } $txt .= "[" . $v[0] . "] " . $v[1]; } if (DAV_EXCH_DEBUG) { CDav::WriteToLog("ERROR: " . $txt, "SC"); } } $tmpNumItems++; } while ($arUserTmp = $dbUserListTmp->Fetch()); } if (DAV_EXCH_DEBUG) { CDav::WriteToLog("Sync " . intval($tmpNumItems) . " items", "SC"); } } if (DAV_EXCH_DEBUG) { CDav::WriteToLog("EXCHANGE contacts sync finished", "SC"); } return "CDavExchangeContacts::DataSync();"; }