Пример #1
1
 public static function GetRentNumbers()
 {
     $arResult = array();
     $viHttp = new CVoxImplantHttp();
     $result = $viHttp->GetPhoneNumbers();
     if ($result && !empty($result->result)) {
         foreach ($result->result as $value) {
             $renewalDate = $renewalDateTs = '';
             if ($value->phone_next_renewal) {
                 $data = new Bitrix\Main\Type\DateTime($value->phone_next_renewal . ' 00:00:00', 'Y-m-d H:i:s');
                 $renewalDate = $data->format(Bitrix\Main\Type\Date::getFormat());
                 $renewalDateTs = $data->getTimestamp();
             }
             $unverifiedHoldDate = $unverifiedHoldDateTs = '';
             if ($value->verification_status != 'VERIFIED' && $value->unverified_hold_until) {
                 $data = new Bitrix\Main\Type\DateTime($value->unverified_hold_until . ' 00:00:00', 'Y-m-d H:i:s');
                 $unverifiedHoldDate = $data->format(Bitrix\Main\Type\Date::getFormat());
                 $unverifiedHoldDateTs = $data->getTimestamp();
             }
             $arResult[$value->phone_number] = array('ACTIVE' => $value->deactivated ? 'N' : 'Y', 'NUMBER' => '+' . $value->phone_number, 'PAID_BEFORE' => $renewalDate, 'PAID_BEFORE_TS' => $renewalDateTs, 'PRICE' => $value->phone_price, 'VERIFY_STATUS' => $value->verification_status, 'VERIFY_STATUS_NAME' => CVoxImplantDocuments::GetStatusName($value->verification_status), 'VERIFY_BEFORE' => $unverifiedHoldDate, 'VERIFY_BEFORE_TS' => $unverifiedHoldDateTs);
         }
     }
     return $arResult;
 }
 public function filter()
 {
     \Bitrix\Main\Loader::includeModule('sale');
     $daysBasketForgotten = $this->getFieldValue('DAYS_BASKET_FORGOTTEN');
     if (!is_numeric($daysBasketForgotten)) {
         $daysBasketForgotten = 90;
     }
     $dateFrom = new \Bitrix\Main\Type\DateTime();
     $dateTo = new \Bitrix\Main\Type\DateTime();
     $dateFrom->setTime(0, 0, 0)->add('-' . $daysBasketForgotten . ' days');
     $dateTo->setTime(0, 0, 0)->add('1 days')->add('-' . $daysBasketForgotten . ' days');
     if ($this->isRunForOldData()) {
         $filter = array('<MIN_DATE_INSERT' => $dateTo->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT));
     } else {
         $filter = array('>MIN_DATE_INSERT' => $dateFrom->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT), '<MIN_DATE_INSERT' => $dateTo->format(\Bitrix\Main\UserFieldTable::MULTIPLE_DATETIME_FORMAT));
     }
     $filter = $filter + array('!FUSER.USER_ID' => null, '=ORDER_ID' => null, '=LID' => $this->getSiteId());
     $userListDb = \Bitrix\Sale\BasketTable::getList(array('select' => array('USER_ID' => 'FUSER.USER_ID', 'EMAIL' => 'FUSER.USER.EMAIL', 'FUSER_USER_NAME' => 'FUSER.USER.NAME'), 'filter' => $filter, 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('MIN_DATE_INSERT', 'MIN(%s)', 'DATE_INSERT')), 'order' => array('USER_ID' => 'ASC')));
     if ($userListDb->getSelectedRowsCount() > 0) {
         $userListDb->addFetchDataModifier(array($this, 'getFetchDataModifier'));
         $this->recipient = $userListDb;
         return true;
     } else {
         return false;
     }
 }
Пример #3
0
 public function GetStatus()
 {
     $ViHttp = new CVoxImplantHttp();
     $result = $ViHttp->GetDocumentStatus();
     if (!$result) {
         $this->error = new CVoxImplantError(__METHOD__, $ViHttp->GetError()->code, $ViHttp->GetError()->msg);
         return false;
     }
     $verifications = array();
     foreach ($result as $key => $verification) {
         $regionName = GetMessage('VI_DOCS_COUNTRY_' . $verification->REGION);
         $regionName = strlen($regionName) > 0 ? $regionName : $verification->REGION;
         $verifications[$key]['REGION'] = $verification->REGION;
         $verifications[$key]['REGION_NAME'] = $regionName;
         $verifications[$key]['STATUS'] = $verification->STATUS;
         $verifications[$key]['STATUS_NAME'] = GetMessage('VI_DOCS_STATUS_' . $verification->STATUS);
         if ($verification->STATUS != 'VERIFIED' && $verification->UNVERIFIED_HOLD_UNTIL) {
             $data = new Bitrix\Main\Type\DateTime($verification->UNVERIFIED_HOLD_UNTIL, 'Y-m-d H:i:s');
             $verifications[$key]['UNVERIFIED_HOLD_UNTIL'] = $data->format(Bitrix\Main\Type\Date::getFormat());
         } else {
             $verifications[$key]['UNVERIFIED_HOLD_UNTIL'] = '';
         }
         if (isset($verification->DOCUMENTS)) {
             foreach ($verification->DOCUMENTS as $document) {
                 $data = new Bitrix\Main\Type\DateTime($document->UPLOADED, 'Y-m-d H:i:s');
                 $verifications[$key]['DOCUMENTS'][] = array('UPLOADED' => $data->format(Bitrix\Main\Type\DateTime::getFormat()), 'DOCUMENT_ID' => $document->DOCUMENT_ID, 'DOCUMENT_STATUS' => $document->DOCUMENT_STATUS, 'DOCUMENT_STATUS_NAME' => GetMessage('VI_DOCS_DOCUMENT_STATUS_' . $document->DOCUMENT_STATUS), 'IS_INDIVIDUAL' => $document->IS_INDIVIDUAL, 'IS_INDIVIDUAL_NAME' => GetMessage('VI_DOCS_IS_INDIVIDUAL_' . $document->IS_INDIVIDUAL), 'REVIEWER_COMMENT' => $document->REVIEWER_COMMENT);
             }
         }
     }
     return $verifications;
 }
Пример #4
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;
 }
Пример #5
0
	function Update($entity_id, $ID, $arFields, $user_id = false)
	{
		global $DB;

		$result = false;

		$entity_id = preg_replace("/[^0-9A-Z_]+/", "", $entity_id);

		$arUpdate = array();
		$arBinds = array();
		$arInsert = array();
		$arInsertType = array();
		$arDelete = array();
		$arUserFields = $this->GetUserFields($entity_id, $ID, false, $user_id);
		foreach($arUserFields as $FIELD_NAME=>$arUserField)
		{
			if(array_key_exists($FIELD_NAME, $arFields))
			{
				$arUserField['VALUE_ID'] = $ID;
				if($arUserField["MULTIPLE"] == "N")
				{
					if(is_callable(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesave")))
						$arFields[$FIELD_NAME] = call_user_func_array(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesave"), array($arUserField, $arFields[$FIELD_NAME], $user_id));

					if(strlen($arFields[$FIELD_NAME])>0)
						$arUpdate[$FIELD_NAME] = $arFields[$FIELD_NAME];
					else
						$arUpdate[$FIELD_NAME] = false;
				}
				elseif(is_array($arFields[$FIELD_NAME]))
				{
					$arInsert[$arUserField["ID"]] = array();
					$arInsertType[$arUserField["ID"]] = $arUserField["USER_TYPE"];

					if(is_callable(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesaveall")))
						$arInsert[$arUserField["ID"]] = call_user_func_array(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesaveall"), array($arUserField, $arFields[$FIELD_NAME], $user_id));
					else
					{
						foreach($arFields[$FIELD_NAME] as $value)
						{
							if(is_callable(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesave")))
								$value = call_user_func_array(array($arUserField["USER_TYPE"]["CLASS_NAME"], "onbeforesave"), array($arUserField, $value, $user_id));

							if(strlen($value)>0)
							{
								switch($arInsertType[$arUserField["ID"]]["BASE_TYPE"])
								{
									case "int":
									case "file":
									case "enum":
										$value = intval($value);
										break;
									case "double":
										$value = doubleval($value);
										break;
									case "datetime":
										//TODO: convert to valid site date/time
										//$value = $DB->CharToDateFunction($value);
										break;
									default:
										// For SQL will follow
										$value = substr($value, 0, 2000);
								}
								$arInsert[$arUserField["ID"]][] = $value;
							}
						}
					}

					if ($arUserField['USER_TYPE_ID'] == 'datetime')
					{
						$serialized = \Bitrix\Main\UserFieldTable::serializeMultipleDatetime($arInsert[$arUserField["ID"]]);
					}
					elseif ($arUserField['USER_TYPE_ID'] == 'date')
					{
						$serialized = \Bitrix\Main\UserFieldTable::serializeMultipleDate($arInsert[$arUserField["ID"]]);
					}
					else
					{
						$serialized = serialize($arInsert[$arUserField["ID"]]);
					}

					$arBinds[$FIELD_NAME] = $arUpdate[$FIELD_NAME] = $serialized;

					$arDelete[$arUserField["ID"]] = true;
				}
			}
		}

		$lower_entity_id = strtolower($entity_id);

		if(!empty($arUpdate))
			$strUpdate = $DB->PrepareUpdate("b_uts_".$lower_entity_id, $arUpdate);
		else
			return $result;

		if(strlen($strUpdate) > 0)
		{
			$result = true;
			$rs = $DB->QueryBind("UPDATE b_uts_".$lower_entity_id." SET ".$strUpdate." WHERE VALUE_ID = ".intval($ID), $arBinds);
			$rows = $rs->AffectedRowsCount();
		}
		else
		{
			$rows = 0;
		}

		if(intval($rows)<=0)
		{
			$rs = $DB->Query("SELECT 'x' FROM b_uts_".$lower_entity_id." WHERE VALUE_ID = ".intval($ID), false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);
			if($rs->Fetch())
				$rows = 1;
		}

		if($rows <= 0)
		{
			$arUpdate["ID"] = $arUpdate["VALUE_ID"] = $ID;
			$DB->Add("b_uts_".$lower_entity_id, $arUpdate, array_keys($arBinds));
		}
		else
		{
			foreach($arDelete as $key=>$value)
			{
				$DB->Query("DELETE from b_utm_".$lower_entity_id." WHERE FIELD_ID = ".intval($key)." AND VALUE_ID = ".intval($ID), false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);
			}
		}

		foreach($arInsert as $FieldId=>$arField)
		{
			switch($arInsertType[$FieldId]["BASE_TYPE"])
			{
				case "int":
				case "file":
				case "enum":
					$COLUMN = "VALUE_INT";
					break;
				case "double":
					$COLUMN = "VALUE_DOUBLE";
					break;
				case "datetime":
					$COLUMN = "VALUE_DATE";
					break;
				default:
					$COLUMN = "VALUE";
			}
			foreach($arField as $value)
			{
				if ($value instanceof \Bitrix\Main\Type\Date)
				{
					// little hack to avoid timezone vs 00:00:00 ambiguity. for utm only
					$value = new \Bitrix\Main\Type\DateTime($value->format('Y-m-d H:i:s'), 'Y-m-d H:i:s');
				}

				switch($arInsertType[$FieldId]["BASE_TYPE"])
				{
					case "int":
					case "file":
					case "enum":
						break;
					case "double":
						break;
					case "datetime":
						$value = $DB->CharToDateFunction($value);
						break;
					default:
						$value = "'".$DB->ForSql($value)."'";
				}
				$DB->Query("INSERT INTO b_utm_".$lower_entity_id." (VALUE_ID, FIELD_ID, ".$COLUMN.")
					VALUES (".intval($ID).", '".$FieldId."', ".$value.")", false, "FILE: ".__FILE__."<br>LINE: ".__LINE__);
			}
		}

		return $result;
	}
Пример #6
0
 public static function getFormatDate($value)
 {
     if (!is_set($value)) {
         return null;
     }
     $setValue = $value;
     if ($value instanceof DateTime || $value instanceof Date) {
         $setValue = $value->toString();
     }
     /** @var \Bitrix\Main\Type\DateTime $time */
     $time = new Bitrix\Main\Type\DateTime($setValue);
     if (self::getVersionSchema() >= self::PARTIAL_VERSION) {
         $format = 'Y-m-d\\TH:i:s';
     } else {
         $format = 'd.m.Y H:i:s';
     }
     return $time->format($format);
 }
Пример #7
0
        $rem = $abtest['MIN_AMOUNT'] - min($testCapacity);
        $est = $rem > 0 ? $rem / ($siteCapacity['daily'] / 2) : 0;
        $estDays = ceil(100 * $est / $abtest['PORTION']);
    }
}
$end_date = null;
if ($abtest['ACTIVE'] == 'Y' && $abtest['DURATION'] != 0) {
    if ($abtest['DURATION'] > 0) {
        $end = clone $abtest['START_DATE'];
        $end->add(intval($abtest['DURATION']) . ' days');
        $end_date = $end->format(Bitrix\Main\Type\Date::convertFormatToPhp($arLang['FORMAT_DATE']));
    } else {
        if (isset($estDays)) {
            $end = new Bitrix\Main\Type\DateTime();
            $end->add($estDays . ' days');
            $end_date = $end->format(Bitrix\Main\Type\Date::convertFormatToPhp($arLang['FORMAT_DATE']));
        } else {
            $end_date = getMessage('ABTEST_DURATION_NA');
        }
    }
}
function pvalue($p1, $p2, $n1, $n2)
{
    $dx = array(1.0, 0.049867347, 0.0211410061, 0.0032776263, 3.80036E-5, 4.88906E-5, 5.383E-6);
    $stdError = sqrt($p1 * (1 - $p1) / $n1 + $p2 * (1 - $p2) / $n2);
    $zval = abs($p2 - $p1) / $stdError;
    for ($pval = 0, $i = 6; $i >= 0; $i--) {
        $pval = $pval * $zval + $dx[$i];
    }
    $pval = pow($pval, -16);
    $pval = 0.5 - abs($pval - 0.5);
Пример #8
0
 public static function AddLead($params)
 {
     if (!CModule::IncludeModule('crm')) {
         return false;
     }
     if (strlen($params['PHONE_NUMBER']) <= 0 || intval($params['USER_ID']) <= 0) {
         return false;
     }
     $dateNow = new Bitrix\Main\Type\DateTime();
     $title = GetMessage($params['INCOMING'] ? 'VI_CRM_CALL_INCOMING' : 'VI_CRM_CALL_OUTGOING');
     $arFields = array('TITLE' => $title . ' ' . $dateNow->format('H:i d.m.Y'), 'OPENED' => 'Y', 'PHONE_WORK' => $params['PHONE_NUMBER']);
     $statuses = CCrmStatus::GetStatusList("SOURCE");
     if (isset($statuses['CALL'])) {
         $arFields['SOURCE_ID'] = 'CALL';
     }
     $portalNumbers = CVoxImplantConfig::GetPortalNumbers();
     $portalNumber = isset($portalNumbers[$params['SEARCH_ID']]) ? $portalNumbers[$params['SEARCH_ID']] : '';
     if ($portalNumber) {
         $arFields['SOURCE_DESCRIPTION'] = GetMessage('VI_CRM_CALL_TO_PORTAL_NUMBER', array('#PORTAL_NUMBER#' => $portalNumber));
     }
     $arFields['FM'] = CCrmFieldMulti::PrepareFields($arFields);
     $CCrmLead = new CCrmLead(false);
     $ID = $CCrmLead->Add($arFields, true, array('CURRENT_USER' => $params['USER_ID'], 'DISABLE_USER_FIELD_CHECK' => true));
     $arErrors = array();
     CCrmBizProcHelper::AutoStartWorkflows(CCrmOwnerType::Lead, $ID, CCrmBizProcEventType::Create, $arErrors);
     CVoxImplantHistory::WriteToLog($arFields, 'LEAD CREATED');
     return $ID;
 }
Пример #9
0
 public static function ConvertFromDB($arProperty, $value, $format = '')
 {
     if (strlen($value["VALUE"]) > 0) {
         try {
             $time = new Bitrix\Main\Type\DateTime($value['VALUE'], "Y-m-d H:i:s");
             $time->toUserTime();
             if ($format === 'SHORT') {
                 $phpFormat = $time->convertFormatToPhp(FORMAT_DATE);
             } elseif ($format === 'FULL') {
                 $phpFormat = $time->convertFormatToPhp(FORMAT_DATETIME);
             } elseif ($format) {
                 $phpFormat = $time->convertFormatToPhp($format);
             } else {
                 $phpFormat = $time->getFormat();
             }
             $value["VALUE"] = $time->format($phpFormat);
             $value["VALUE"] = str_replace(" 00:00:00", "", $value["VALUE"]);
         } catch (Bitrix\Main\ObjectException $e) {
         }
     }
     return $value;
 }
Пример #10
0
	public static function ConvertFromDB($arProperty, $value, $format = '')
	{
		if (strlen($value["VALUE"]) > 0)
		{
			try
			{
				$time = new Bitrix\Main\Type\DateTime($value['VALUE'], "Y-m-d H:i:s", new \DateTimeZone('UTC'));
				$time->setDefaultTimeZone();

				$phpFormat = $format? $time->convertFormatToPhp($format): $time->getFormat();

				$value["VALUE"] = $time->format($phpFormat);
				$value["VALUE"] = str_replace(" 00:00:00", "", $value["VALUE"]);
			}
			catch(Main\ObjectException $e)
			{
			}
		}

		return $value;
	}