Exemplo n.º 1
0
 public static function sipAdd($arParams, $nav, $server)
 {
     if (!CVoxImplantMain::CheckAccess()) {
         throw new \Bitrix\Rest\AccessException();
     }
     $arParams = array_change_key_case($arParams, CASE_UPPER);
     if (!isset($arParams['TYPE'])) {
         $arParams['TYPE'] = CVoxImplantSip::TYPE_CLOUD;
     }
     $viSip = new CVoxImplantSip();
     $configId = $viSip->Add(array('TYPE' => strtolower($arParams['TYPE']), 'PHONE_NAME' => $arParams['TITLE'], 'SERVER' => $arParams['SERVER'], 'LOGIN' => $arParams['LOGIN'], 'PASSWORD' => $arParams['PASSWORD'], 'APP_ID' => $server->getAppId()));
     if (!$configId || $viSip->GetError()->error) {
         throw new Bitrix\Rest\RestException($viSip->GetError()->msg, $viSip->GetError()->code, CRestServer::STATUS_WRONG_REQUEST);
     }
     $result = $viSip->Get($configId, array('WITH_TITLE' => true));
     unset($result['APP_ID']);
     unset($result['REG_STATUS']);
     return $result;
 }
Exemplo n.º 2
0
 public static function GetConfigBySearchId($searchId)
 {
     if (strlen($searchId) <= 0) {
         return array('ERROR' => 'Config is`t found for undefined number');
     }
     $orm = VI\ConfigTable::getList(array('filter' => array('=SEARCH_ID' => (string) $searchId)));
     $config = $orm->fetch();
     if (!$config) {
         $result = array('ERROR' => 'Config is`t found for number: ' . $searchId);
     } 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_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']);
     }
     return $result;
 }
Exemplo n.º 3
0
/********************************************************************
				/Input params
********************************************************************/
$arResult = array("ITEM" => Bitrix\Voximplant\ConfigTable::getById($arParams["ID"])->fetch(), "QUEUE" => array(), "SIP_CONFIG" => array(), "~QUEUE" => array());
if (!!$arResult["ITEM"]) {
    if (!empty($arResult["ITEM"]["WORKTIME_DAYOFF"])) {
        $arResult["ITEM"]["WORKTIME_DAYOFF"] = explode(",", $arResult["ITEM"]["WORKTIME_DAYOFF"]);
    }
    $db_res = Bitrix\Voximplant\QueueTable::getList(array('filter' => array('=CONFIG_ID' => $arResult["ITEM"]["ID"])));
    while ($res = $db_res->fetch()) {
        $arResult["QUEUE"][$res["USER_ID"]] = $res;
        $arResult["~QUEUE"][$res["ID"]] = $res["USER_ID"];
    }
    if ($arResult["ITEM"]["PORTAL_MODE"] == CVoxImplantConfig::MODE_SIP) {
        $viSip = new CVoxImplantSip();
        $arResult["SIP_CONFIG"] = $viSip->Get($arParams["ID"]);
        $arResult["SIP_CONFIG"]['PHONE_NAME'] = $arResult['ITEM']['PHONE_NAME'];
    }
}
if (empty($arResult["ITEM"])) {
    return;
}
if ($_REQUEST["action"] == "save" && check_bitrix_sessid()) {
    $post = \Bitrix\Main\Context::getCurrent()->getRequest()->getPostList()->toArray();
    $skipSaving = false;
    $arFieldsSip = array();
    if (isset($post['SIP'])) {
        $viSip = new CVoxImplantSip();
        $result = $viSip->Update($arParams["ID"], array('TYPE' => $arResult["SIP_CONFIG"]["TYPE"], 'PHONE_NAME' => $post['SIP']['PHONE_NAME'], 'SERVER' => $post['SIP']['SERVER'], 'LOGIN' => $post['SIP']['LOGIN'], 'PASSWORD' => $post['SIP']['PASSWORD'], 'NEED_UPDATE' => $post['SIP']['NEED_UPDATE']));
        $skipSaving = !$result;
        $arFieldsSip = array('PHONE_NAME' => $post['SIP']['PHONE_NAME'], 'SERVER' => $post['SIP']['SERVER'], 'LOGIN' => $post['SIP']['LOGIN'], 'PASSWORD' => $post['SIP']['PASSWORD']);