Ejemplo n.º 1
0
 public static function GetRecordLimit($mode = false)
 {
     $sipConnectorActive = CVoxImplantConfig::GetModeStatus(CVoxImplantConfig::MODE_SIP);
     $recordLimit = COption::GetOptionInt("voximplant", "record_limit");
     if ($recordLimit > 0 && !CVoxImplantAccount::IsPro()) {
         if ($mode == CVoxImplantConfig::MODE_SIP && $sipConnectorActive) {
             $recordLimitEnable = false;
         } else {
             $recordLimitEnable = true;
             $recordLimitRemaining = $recordLimit - CGlobalCounter::GetValue('vi_records', CGlobalCounter::ALL_SITES);
             $result = array('ENABLE' => $recordLimitEnable, 'LIMIT' => $recordLimit, 'REMAINING' => $recordLimitRemaining);
         }
     } else {
         $recordLimitEnable = false;
     }
     if (!$recordLimitEnable) {
         $result = array('ENABLE' => $recordLimitEnable, 'DEMO' => CVoxImplantAccount::IsDemo() && !$sipConnectorActive);
     }
     return $result;
 }
Ejemplo n.º 2
0
 public function Add($arParams)
 {
     global $DB;
     $chatTitle = '';
     if (isset($arParams['TITLE'])) {
         $chatTitle = trim($arParams['TITLE']);
     }
     $userId = array();
     if (isset($arParams['USERS'])) {
         $userId = $arParams['USERS'];
     }
     $callNumber = '';
     if (isset($arParams['CALL_NUMBER'])) {
         $callNumber = $arParams['CALL_NUMBER'];
     }
     $entityType = '';
     if (isset($arParams['ENTITY_TYPE'])) {
         $entityType = $arParams['ENTITY_TYPE'];
     }
     $entityId = '';
     if (isset($arParams['ENTITY_ID'])) {
         $entityId = $arParams['ENTITY_ID'];
     }
     $type = IM_MESSAGE_CHAT;
     if (isset($arParams['TYPE']) && in_array($arParams['TYPE'], array(IM_MESSAGE_OPEN, IM_MESSAGE_CHAT))) {
         $type = $arParams['TYPE'];
     }
     $skipUserAdd = false;
     if ($userId === false) {
         $skipUserAdd = true;
     }
     $arUserId = array();
     if (is_array($userId)) {
         $arUserId = \CIMContactList::PrepareUserIds($userId);
     } else {
         if (intval($userId) > 0) {
             $arUserId[intval($userId)] = intval($userId);
         }
     }
     $arUserId[$this->user_id] = $this->user_id;
     if (!$skipUserAdd) {
         if (count($arUserId) <= 2) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MIN_USER"), "MIN_USER");
             return false;
         }
         if (count($arUserId) > 300) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MAX_USER", array('#COUNT#' => 300)), "MAX_USER");
             return false;
         }
         if (!IsModuleInstalled('intranet') && CModule::IncludeModule('socialnetwork') && CSocNetUser::IsFriendsAllowed()) {
             global $USER;
             $arFriendUsers = array();
             $dbFriends = CSocNetUserRelations::GetList(array(), array("USER_ID" => $USER->GetID(), "RELATION" => SONET_RELATIONS_FRIEND), false, false, array("ID", "FIRST_USER_ID", "SECOND_USER_ID", "DATE_CREATE", "DATE_UPDATE", "INITIATED_BY"));
             while ($arFriends = $dbFriends->Fetch()) {
                 $friendId = $USER->GetID() == $arFriends["FIRST_USER_ID"] ? $arFriends["SECOND_USER_ID"] : $arFriends["FIRST_USER_ID"];
                 $arFriendUsers[$friendId] = $friendId;
             }
             foreach ($arUserId as $id => $userId) {
                 if ($userId == $USER->GetID()) {
                     continue;
                 }
                 if (!isset($arFriendUsers[$userId]) && CIMSettings::GetPrivacy(CIMSettings::PRIVACY_CHAT, $userId) == CIMSettings::PRIVACY_RESULT_CONTACT) {
                     unset($arUserId[$id]);
                 }
             }
             if (count($arUserId) <= 2) {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_ERROR_MIN_USER_BY_PRIVACY"), "MIN_USER_BY_PRIVACY");
                 return false;
             }
         }
     }
     $arUsers = CIMContactList::GetUserData(array('ID' => array_values($arUserId), 'DEPARTMENT' => 'N', 'USE_CACHE' => 'N'));
     $arUsers = $arUsers['users'];
     $arUsersName = array();
     if ($chatTitle == "") {
         if (IM\Color::isEnabled()) {
             CGlobalCounter::Increment('im_chat_color_id', CGlobalCounter::ALL_SITES, false);
             $chatColorId = CGlobalCounter::GetValue('im_chat_color_id', CGlobalCounter::ALL_SITES);
             $chatColorCode = \Bitrix\Im\Color::getCodeByNumber($chatColorId);
             CGlobalCounter::Increment('im_chat_color_' . $chatColorCode, CGlobalCounter::ALL_SITES, false);
             $chatColorCodeCount = CGlobalCounter::GetValue('im_chat_color_' . $chatColorCode, CGlobalCounter::ALL_SITES);
             if ($chatColorCodeCount == 100) {
                 CGlobalCounter::Set('im_chat_color_' . $chatColorCode, 1, CGlobalCounter::ALL_SITES, '', false);
                 $chatColorId = 1;
             }
             $chatTitle = GetMessage('IM_CHAT_NAME_FORMAT', array('#COLOR#' => \Bitrix\Im\Color::getName($chatColorCode), '#NUMBER#' => $chatColorCodeCount));
         } else {
             foreach ($arUserId as $userId) {
                 $arUsersName[$userId] = htmlspecialcharsback($arUsers[$userId]['name']);
             }
             $chatTitle = implode(', ', $arUsersName);
         }
     }
     $isExtranet = false;
     foreach ($arUsers as $userData) {
         if ($userData['extranet']) {
             $isExtranet = true;
             break;
         }
     }
     $result = IM\ChatTable::add(array("TITLE" => substr($chatTitle, 0, 255), "TYPE" => $type, "COLOR" => $chatColorCode, "AUTHOR_ID" => $this->user_id, "ENTITY_TYPE" => $entityType, "ENTITY_ID" => $entityId, "EXTRANET" => $isExtranet ? 'Y' : 'N', "CALL_NUMBER" => $callNumber));
     $chatId = $result->getId();
     if ($chatId > 0) {
         $params = $result->getData();
         if (intval($params['AVATAR']) > 0) {
             $this->lastAvatarId = $params['AVATAR'];
         }
         $arUsersName = array();
         foreach ($arUserId as $userId) {
             if ($userId != $this->user_id) {
                 $arUsersName[$userId] = htmlspecialcharsback($arUsers[$userId]['name']);
             }
             CIMContactList::SetRecent(array('ENTITY_ID' => $chatId, 'MESSAGE_ID' => 0, 'CHAT_TYPE' => $params['TYPE'], 'USER_ID' => $userId));
             IM\RelationTable::add(array("CHAT_ID" => $chatId, "MESSAGE_TYPE" => $params['TYPE'], "USER_ID" => $userId, "STATUS" => IM_STATUS_READ));
             CIMContactList::CleanChatCache($userId);
         }
         if (!$skipUserAdd) {
             $message = GetMessage("IM_CHAT_JOIN_" . $arUsers[$this->user_id]['gender'], array('#USER_1_NAME#' => htmlspecialcharsback($arUsers[$this->user_id]['name']), '#USER_2_NAME#' => implode(', ', $arUsersName)));
             self::AddMessage(array("TO_CHAT_ID" => $chatId, "FROM_USER_ID" => $this->user_id, "MESSAGE" => $message, "SYSTEM" => 'Y'));
         }
     } else {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("IM_IM_ERROR_EMPTY_USER_OR_CHAT"), "ERROR_OF_CREATE_CHAT");
         return false;
     }
     return $chatId;
 }
Ejemplo n.º 3
0
 public static function Add($params)
 {
     if (strlen($params["CALL_ID"]) > 0) {
         $res = VI\CallTable::getList(array('select' => array('ID', 'DATE_CREATE', 'CRM', 'CONFIG_ID', 'USER_ID', 'TRANSFER_USER_ID'), 'filter' => array('=CALL_ID' => $params["CALL_ID"])));
         if ($call = $res->fetch()) {
             VI\CallTable::delete($call['ID']);
         }
     }
     $arFields = array("ACCOUNT_ID" => $params["ACCOUNT_ID"], "APPLICATION_ID" => $params["APPLICATION_ID"], "APPLICATION_NAME" => $params["APPLICATION_NAME"], "INCOMING" => $params["INCOMING"], "CALL_START_DATE" => $call ? $call['DATE_CREATE'] : new Bitrix\Main\Type\DateTime(), "CALL_DURATION" => $params["CALL_DURATION"], "CALL_STATUS" => $params["CALL_STATUS"], "CALL_FAILED_CODE" => $params["CALL_FAILED_CODE"], "CALL_FAILED_REASON" => $params["CALL_FAILED_REASON"], "COST" => $params["COST_FINAL"], "COST_CURRENCY" => $params["COST_CURRENCY"], "CALL_VOTE" => intval($params["CALL_VOTE"]), "CALL_ID" => $params["CALL_ID"], "CALL_CATEGORY" => $params["CALL_CATEGORY"]);
     if (intval($params["PORTAL_USER_ID"]) > 0) {
         $arFields["PORTAL_USER_ID"] = intval($params["PORTAL_USER_ID"]);
     }
     if (strlen($params["PHONE_NUMBER"]) > 0) {
         $arFields["PHONE_NUMBER"] = $params["PHONE_NUMBER"];
     }
     if (strlen($params["CALL_DIRECTION"]) > 0) {
         $arFields["CALL_DIRECTION"] = $params["CALL_DIRECTION"];
     }
     if (strlen($params["PORTAL_NUMBER"]) > 0) {
         $arFields["PORTAL_NUMBER"] = $params["PORTAL_NUMBER"];
     }
     if (strlen($params["ACCOUNT_SEARCH_ID"]) > 0) {
         $arFields["PORTAL_NUMBER"] = $params["ACCOUNT_SEARCH_ID"];
     }
     if (strlen($params["CALL_LOG"]) > 0) {
         $arFields["CALL_LOG"] = $params["CALL_LOG"];
     }
     $orm = Bitrix\VoxImplant\StatisticTable::add($arFields);
     if (!$orm) {
         return false;
     }
     if ($call && intval($arFields["PORTAL_USER_ID"]) <= 0) {
         $res = VI\QueueTable::getList(array('select' => array('ID', 'USER_ID'), 'order' => array('LAST_ACTIVITY_DATE' => 'asc'), 'filter' => array('=CONFIG_ID' => $call['CONFIG_ID']), 'limit' => 1));
         $queueUser = $res->fetch();
         if ($queueUser) {
             $arFields["PORTAL_USER_ID"] = $queueUser['USER_ID'];
         }
     }
     if (strlen($arFields["PHONE_NUMBER"]) > 0 && $arFields["PORTAL_USER_ID"] > 0 && $params["CALL_FAILED_CODE"] != 423) {
         $plusSymbol = strlen($arFields["PHONE_NUMBER"]) >= 10 ? '+' : '';
         if ($arFields["INCOMING"] == CVoxImplantMain::CALL_OUTGOING) {
             if ($arFields['CALL_FAILED_CODE'] == '603-S') {
                 $message = GetMessage('VI_OUT_CALL_DECLINE_SELF', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
             } else {
                 if ($arFields['CALL_FAILED_CODE'] == 603) {
                     $message = GetMessage('VI_OUT_CALL_DECLINE', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                 } else {
                     if ($arFields['CALL_FAILED_CODE'] == 486) {
                         $message = GetMessage('VI_OUT_CALL_BUSY', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                     } else {
                         if ($arFields['CALL_FAILED_CODE'] == 480) {
                             $message = GetMessage('VI_OUT_CALL_UNAVAILABLE', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                         } else {
                             if ($arFields['CALL_FAILED_CODE'] == 404 || $arFields['CALL_FAILED_CODE'] == 484) {
                                 $message = GetMessage('VI_OUT_CALL_ERROR_NUMBER', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                             } else {
                                 if ($arFields['CALL_FAILED_CODE'] == 402) {
                                     $message = GetMessage('VI_OUT_CALL_NO_MONEY', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"]));
                                 } else {
                                     $message = GetMessage('VI_OUT_CALL_END', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]'));
                                 }
                             }
                         }
                     }
                 }
             }
         } else {
             if ($arFields['CALL_FAILED_CODE'] == 304) {
                 if (strlen($params['URL']) > 0) {
                     $subMessage = GetMessage('VI_CALL_VOICEMAIL', array('#LINK_START#' => '[PCH=' . $orm->getId() . ']', '#LINK_END#' => '[/PCH]'));
                 } else {
                     $subMessage = '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]';
                 }
                 $message = GetMessage('VI_IN_CALL_SKIP', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => $subMessage));
             } else {
                 $message = GetMessage('VI_IN_CALL_END', array('#NUMBER#' => $plusSymbol . $arFields["PHONE_NUMBER"], '#INFO#' => '[PCH=' . $orm->getId() . ']' . GetMessage('VI_CALL_INFO') . '[/PCH]'));
             }
         }
         self::SendMessageToChat($arFields["PORTAL_USER_ID"], $arFields["PHONE_NUMBER"], $arFields["INCOMING"], $message);
     }
     if ($call['CRM'] == 'Y') {
         CVoxImplantCrmHelper::UpdateCall($arFields);
     }
     if (strlen($params['URL']) > 0) {
         $attachToCrm = $call['CRM'] == 'Y';
         $startDownloadAgent = false;
         $recordLimit = COption::GetOptionInt("voximplant", "record_limit");
         if ($recordLimit > 0 && !CVoxImplantAccount::IsPro()) {
             $sipConnectorActive = CVoxImplantConfig::GetModeStatus(CVoxImplantConfig::MODE_SIP);
             if ($params['PORTAL_TYPE'] == CVoxImplantConfig::MODE_SIP && $sipConnectorActive) {
                 $startDownloadAgent = true;
             } else {
                 $recordMonth = COption::GetOptionInt("voximplant", "record_month");
                 if (!$recordMonth) {
                     $recordMonth = date('Ym');
                     COption::SetOptionInt("voximplant", "record_month", $recordMonth);
                 }
                 $recordCount = CGlobalCounter::GetValue('vi_records', CGlobalCounter::ALL_SITES);
                 if ($recordCount < $recordLimit) {
                     CGlobalCounter::Increment('vi_records', CGlobalCounter::ALL_SITES, false);
                     $startDownloadAgent = true;
                 } else {
                     if ($recordMonth < date('Ym')) {
                         COption::SetOptionInt("voximplant", "record_month", date('Ym'));
                         CGlobalCounter::Set('vi_records', 1, CGlobalCounter::ALL_SITES, false);
                         CGlobalCounter::Set('vi_records_skipped', 0, CGlobalCounter::ALL_SITES, false);
                         $startDownloadAgent = true;
                     } else {
                         CGlobalCounter::Increment('vi_records_skipped', CGlobalCounter::ALL_SITES, false);
                     }
                 }
                 CVoxImplantHistory::WriteToLog(array('limit' => $recordLimit, 'saved' => CGlobalCounter::GetValue('vi_records', CGlobalCounter::ALL_SITES), 'skipped' => CGlobalCounter::GetValue('vi_records_skipped', CGlobalCounter::ALL_SITES), 'save to portal' => $startDownloadAgent ? 'Y' : 'N'), 'STATUS OF RECORD LIMIT');
             }
         } else {
             $startDownloadAgent = true;
         }
         if ($startDownloadAgent) {
             self::DownloadAgent($orm->getId(), $params['URL'], $attachToCrm);
         }
     }
     if (strlen($params["ACCOUNT_PAYED"]) > 0 && in_array($params["ACCOUNT_PAYED"], array('Y', 'N'))) {
         CVoxImplantAccount::SetPayedFlag($params["ACCOUNT_PAYED"]);
     }
     foreach (GetModuleEvents("voximplant", "onCallEnd", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(array('CALL_ID' => $arFields['CALL_ID'], 'CALL_TYPE' => $arFields['INCOMING'], 'PHONE_NUMBER' => $arFields['PHONE_NUMBER'], 'PORTAL_NUMBER' => $arFields['PORTAL_NUMBER'], 'PORTAL_USER_ID' => $arFields['PORTAL_USER_ID'], 'CALL_DURATION' => $arFields['CALL_DURATION'], 'CALL_START_DATE' => $arFields['CALL_START_DATE'], 'COST' => $arFields['COST'], 'COST_CURRENCY' => $arFields['COST_CURRENCY'], 'CALL_FAILED_CODE' => $arFields['CALL_FAILED_CODE'], 'CALL_FAILED_REASON' => $arFields['CALL_FAILED_REASON'])));
     }
     return true;
 }