Exemplo n.º 1
0
 public static function GetConfigByUserId($userId)
 {
     $userId = intval($userId);
     if ($userId > 0) {
         $viUser = new CVoxImplantUser();
         $userInfo = $viUser->GetUserInfo($userId);
         if ($userInfo['user_backphone'] == '') {
             $userInfo['user_backphone'] = CVoxImplantConfig::LINK_BASE_NUMBER;
         }
     } else {
         $userInfo = array();
         $userInfo['user_backphone'] = CVoxImplantConfig::GetPortalNumber();
         $userInfo['user_extranet'] = false;
     }
     if ($userInfo['user_extranet']) {
         $result = array('error' => array('code' => 'EXTRANAET', 'msg' => 'Extranet user can not use telephony'));
     } else {
         if ($userInfo['user_backphone'] == CVoxImplantPhone::GetLinkNumber() || $userInfo['user_backphone'] == CVoxImplantConfig::LINK_BASE_NUMBER) {
             $result = self::GetLinkConfig();
         } else {
             $result = CVoxImplantConfig::GetConfigBySearchId($userInfo['user_backphone']);
             if (isset($result['ERROR']) && strlen($result['ERROR']) > 0) {
                 $result = self::GetLinkConfig();
             }
         }
     }
     $result['USER_ID'] = $userId;
     return $result;
 }
Exemplo n.º 2
0
 public static function GetPortalNumbers()
 {
     $result = array();
     $res = VI\ConfigTable::getList();
     while ($row = $res->fetch()) {
         if (strlen($row['PHONE_NAME']) <= 0) {
             $row['PHONE_NAME'] = substr($row['SEARCH_ID'], 0, 3) == 'reg' ? GetMessage('VI_CONFIG_SIP_CLOUD_DEF') : GetMessage('VI_CONFIG_SIP_OFFICE_DEF');
             $row['PHONE_NAME'] = str_replace('#ID#', $row['ID'], $row['PHONE_NAME']);
         }
         $result[$row['SEARCH_ID']] = htmlspecialcharsbx($row['PHONE_NAME']);
     }
     $linkNumber = CVoxImplantPhone::GetLinkNumber();
     $result['LINK_BASE_NUMBER'] = $linkNumber == '' ? GetMessage('VI_CONFIG_LINK_DEF') : '+' . $linkNumber;
     return $result;
 }
Exemplo n.º 3
0
                    $arSend['ERROR'] = $result;
                }
            }
            echo CUtil::PhpToJsObject($arSend);
        } else {
            if ($_POST['VI_ACTIVATE'] == 'Y') {
                $arSend['ERROR'] = '';
                $result = CVoxImplantPhone::ActivateCallerID(CVoxImplantPhone::GetLinkNumber(), $_POST['CODE']);
                if ($result) {
                    $arSend['NUMBER'] = $result['NUMBER'];
                    $arSend['VERIFIED'] = $result['VERIFIED'];
                    $arSend['VERIFIED_UNTIL'] = ConvertTimeStamp(MakeTimeStamp($result['VERIFIED_UNTIL']) + CTimeZone::GetOffset() + date("Z"), 'FULL');
                } else {
                    $arSend['ERROR'] = 'CONNECT_ERROR';
                }
                echo CUtil::PhpToJsObject($arSend);
            } else {
                if ($_POST['VI_REMOVE'] == 'Y') {
                    $result = CVoxImplantPhone::DelCallerID(CVoxImplantPhone::GetLinkNumber());
                    $arSend['ERROR'] = $result ? '' : 'CONNECT_ERROR';
                    echo CUtil::PhpToJsObject($arSend);
                } else {
                    echo CUtil::PhpToJsObject(array('ERROR' => 'UNKNOWN_ERROR'));
                }
            }
        }
    }
} else {
    echo CUtil::PhpToJsObject(array('BITRIX_SESSID' => bitrix_sessid(), 'ERROR' => 'SESSION_ERROR'));
}
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php";
Exemplo n.º 4
0
 public static function GetConfig($id, $type = self::GET_BY_ID)
 {
     if (strlen($id) <= 0) {
         return array('ERROR' => 'Config is`t found for undefined id/number');
     }
     if ($type == self::GET_BY_SEARCH_ID) {
         $orm = VI\ConfigTable::getList(array('filter' => array('=SEARCH_ID' => (string) $id)));
     } else {
         $orm = VI\ConfigTable::getList(array('filter' => array('=ID' => intval($id))));
     }
     $config = $orm->fetch();
     if (!$config) {
         $result = array('ERROR' => $type == self::GET_BY_SEARCH_ID ? 'Config is`t found for number: ' . $id : 'Config is`t found for id: ' . $id);
     } else {
         $result = $config;
         $result['PHONE_TITLE'] = $result['PHONE_NAME'];
         if ($result['PORTAL_MODE'] == self::MODE_SIP) {
             $viSip = new CVoxImplantSip();
             $sipResult = $viSip->Get($config["ID"]);
             $result['PHONE_NAME'] = preg_replace("/[^0-9\\#\\*]/i", "", $result['PHONE_NAME']);
             $result['PHONE_NAME'] = strlen($result['PHONE_NAME']) >= 4 ? $result['PHONE_NAME'] : '';
             $result['SIP_SERVER'] = $sipResult ? $sipResult['SERVER'] : '';
             $result['SIP_LOGIN'] = $sipResult ? $sipResult['LOGIN'] : '';
             $result['SIP_PASSWORD'] = $sipResult ? $sipResult['PASSWORD'] : '';
         }
         if (strlen($result['FORWARD_LINE']) > 0 && $result['FORWARD_LINE'] != self::FORWARD_LINE_DEFAULT) {
             if ($result['FORWARD_LINE'] == CVoxImplantPhone::GetLinkNumber() || $result['FORWARD_LINE'] == CVoxImplantConfig::LINK_BASE_NUMBER) {
                 $result['FORWARD_LINE_TYPE'] = 'LINK';
                 if ($result['FORWARD_LINE_NUMBER'] == CVoxImplantConfig::LINK_BASE_NUMBER) {
                     $result['FORWARD_LINE_NUMBER'] = '';
                 } else {
                     $result['FORWARD_LINE_NUMBER'] = CVoxImplantPhone::GetLinkNumber();
                 }
             } else {
                 $ormForward = VI\ConfigTable::getList(array('filter' => array('=SEARCH_ID' => (string) $result['FORWARD_LINE'])));
                 $configForward = $ormForward->fetch();
                 CVoxImplantHistory::WriteToLog($configForward);
                 if ($configForward) {
                     $result['FORWARD_LINE_TYPE'] = $configForward['PORTAL_MODE'];
                     if ($result['FORWARD_LINE_TYPE'] == self::MODE_SIP) {
                         $viForwardSip = new CVoxImplantSip();
                         $forwardSipResult = $viForwardSip->Get($configForward["ID"]);
                         $result['FORWARD_LINE_SIP_SERVER'] = $forwardSipResult ? $forwardSipResult['SERVER'] : '';
                         $result['FORWARD_LINE_SIP_LOGIN'] = $forwardSipResult ? $forwardSipResult['LOGIN'] : '';
                         $result['FORWARD_LINE_SIP_PASSWORD'] = $forwardSipResult ? $forwardSipResult['PASSWORD'] : '';
                     } else {
                         $result['FORWARD_LINE_NUMBER'] = $configForward['SEARCH_ID'];
                     }
                 } else {
                     $result['FORWARD_LINE'] = self::FORWARD_LINE_DEFAULT;
                 }
             }
         }
         if (strlen($result['FORWARD_NUMBER']) > 0) {
             $result["FORWARD_NUMBER"] = NormalizePhone($result['FORWARD_NUMBER'], 1);
         }
         if (strlen($result['WORKTIME_DAYOFF_NUMBER']) > 0) {
             $result["WORKTIME_DAYOFF_NUMBER"] = NormalizePhone($result['WORKTIME_DAYOFF_NUMBER'], 1);
         }
         // check work time
         $result['WORKTIME_SKIP_CALL'] = 'N';
         if ($config['WORKTIME_ENABLE'] == 'Y') {
             $timezone = !empty($config["WORKTIME_TIMEZONE"]) ? new DateTimeZone($config["WORKTIME_TIMEZONE"]) : null;
             $numberDate = new Bitrix\Main\Type\DateTime(null, null, $timezone);
             if (!empty($config['WORKTIME_DAYOFF'])) {
                 $daysOff = explode(",", $config['WORKTIME_DAYOFF']);
                 $allWeekDays = array('MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6, 'SU' => 7);
                 $currentWeekDay = $numberDate->format('N');
                 foreach ($daysOff as $day) {
                     if ($currentWeekDay == $allWeekDays[$day]) {
                         $result['WORKTIME_SKIP_CALL'] = "Y";
                     }
                 }
             }
             if ($result['WORKTIME_SKIP_CALL'] !== "Y" && !empty($config['WORKTIME_HOLIDAYS'])) {
                 $holidays = explode(",", $config['WORKTIME_HOLIDAYS']);
                 $currentDay = $numberDate->format('d.m');
                 foreach ($holidays as $holiday) {
                     if ($currentDay == $holiday) {
                         $result['WORKTIME_SKIP_CALL'] = "Y";
                     }
                 }
             }
             if ($result['WORKTIME_SKIP_CALL'] !== "Y" && !empty($config['WORKTIME_FROM']) && !empty($config['WORKTIME_TO'])) {
                 $currentTime = $numberDate->format('G.i');
                 if (!($currentTime >= $config['WORKTIME_FROM'] && $currentTime <= $config['WORKTIME_TO'])) {
                     $result['WORKTIME_SKIP_CALL'] = "Y";
                 }
             }
             if ($result['WORKTIME_SKIP_CALL'] === "Y") {
                 $result['WORKTIME_DAYOFF_MELODY'] = CVoxImplantConfig::GetMelody('WORKTIME_DAYOFF_MELODY', $config['MELODY_LANG'], $config['WORKTIME_DAYOFF_MELODY']);
             }
         }
         if (CVoxImplantHttp::GetPortalType() == CVoxImplantHttp::TYPE_BITRIX24) {
             $result['PORTAL_URL'] = CVoxImplantHttp::GetServerAddress() . '/settings/info_receiver.php?b24_action=phone&b24_direct=y';
         } else {
             $result['PORTAL_URL'] = CVoxImplantHttp::GetServerAddress() . '/services/telephony/info_receiver.php?b24_direct=y';
         }
         $result['PORTAL_SIGN'] = CVoxImplantHttp::GetPortalSign();
         $result['MELODY_WELCOME'] = CVoxImplantConfig::GetMelody('MELODY_WELCOME', $config['MELODY_LANG'], $config['MELODY_WELCOME']);
         $result['MELODY_VOICEMAIL'] = CVoxImplantConfig::GetMelody('MELODY_VOICEMAIL', $config['MELODY_LANG'], $config['MELODY_VOICEMAIL']);
         $result['MELODY_HOLD'] = CVoxImplantConfig::GetMelody('MELODY_HOLD', $config['MELODY_LANG'], $config['MELODY_HOLD']);
         $result['MELODY_WAIT'] = CVoxImplantConfig::GetMelody('MELODY_WAIT', $config['MELODY_LANG'], $config['MELODY_WAIT']);
         $result['MELODY_RECORDING'] = CVoxImplantConfig::GetMelody('MELODY_RECORDING', $config['MELODY_LANG'], $config['MELODY_RECORDING']);
         $result['MELODY_VOTE'] = CVoxImplantConfig::GetMelody('MELODY_VOTE', $config['MELODY_LANG'], $config['MELODY_VOTE']);
         $result['MELODY_VOTE_END'] = CVoxImplantConfig::GetMelody('MELODY_VOTE_END', $config['MELODY_LANG'], $config['MELODY_VOTE_END']);
     }
     return $result;
 }