/** * Load coupons for existing order. * * @return void */ public static function load() { if (self::$useMode != self::MODE_ORDER) { return; } self::$checkActivity = false; $couponsList = array(); $couponIterator = Internals\OrderCouponsTable::getList(array('select' => array('*', 'MODULE' => 'ORDER_DISCOUNT.MODULE_ID', 'DISCOUNT_ID' => 'ORDER_DISCOUNT.DISCOUNT_ID', 'DISCOUNT_NAME' => 'ORDER_DISCOUNT.NAME'), 'filter' => array('=ORDER_ID' => self::$orderId), 'order' => array('ID' => 'ASC'))); while ($coupon = $couponIterator->fetch()) { $couponData = $coupon['DATA']; $couponData['COUPON'] = $coupon['COUPON']; $couponData['STATUS'] = self::STATUS_ENTERED; $couponData['CHECK_CODE'] = self::COUPON_CHECK_OK; $couponData['MODULE'] = $coupon['MODULE']; $couponData['ID'] = $coupon['COUPON_ID']; $couponData['DISCOUNT_ID'] = $coupon['DISCOUNT_ID']; $couponData['DISCOUNT_NAME'] = (string) $coupon['DISCOUNT_NAME']; $couponData['DISCOUNT_ACTIVE'] = 'Y'; $couponData['TYPE'] = $coupon['TYPE']; $couponData['ACTIVE'] = 'Y'; $couponData['SAVED'] = 'Y'; foreach (self::$timeFields as $fieldName) { if (isset($couponData[$fieldName])) { $couponData[$fieldName] = Main\Type\DateTime::createFromTimestamp($couponData[$fieldName]); } } unset($fieldName); if (empty($couponData['USER_INFO']) && $couponData['MODE'] == self::COUPON_MODE_FULL) { $couponData['USER_INFO'] = array('USER_ID' => 0, 'MAX_USE' => 0, 'USE_COUNT' => 0, 'ACTIVE_FROM' => null, 'ACTIVE_TO' => null); } if (!empty($couponData['USER_INFO'])) { foreach (self::$timeFields as $fieldName) { if (isset($couponData['USER_INFO'][$fieldName])) { $couponData['USER_INFO'][$fieldName] = Main\Type\DateTime::createFromTimestamp($couponData['USER_INFO'][$fieldName]); } } unset($fieldName); foreach ($couponData['USER_INFO'] as $fieldName => $fieldValue) { $couponData[$fieldName] = $fieldValue; } } $couponsList[$couponData['COUPON']] = $couponData; } unset($coupon, $couponIterator); if (!empty($couponsList)) { self::setCoupons($couponsList, false); } self::$checkActivity = true; }
/** * Fixes cold start, when we don't have any data in RecentlyUsedTable. * @param mixed|int|User|\CAllUser $user User. * @return bool * @throws \Bitrix\Main\ArgumentException */ private function fixColdStart($user) { $userId = User::resolveUserId($user); if (!$userId) { $this->errorCollection->addOne(new Error('Could not get user id.')); return false; } $storage = Driver::getInstance()->getStorageByUserId($userId); if (!$storage) { $this->errorCollection->addOne(new Error('Could not get storage by user id.')); return false; } $fromDate = DateTime::createFromTimestamp(time() - 14 * 24 * 3600); $objects = array(); $query = FileTable::getList(array('select' => array('ID', 'UPDATE_TIME'), 'filter' => array('STORAGE_ID' => $storage->getId(), 'TYPE' => ObjectTable::TYPE_FILE, 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE, '>UPDATE_TIME' => $fromDate, array('LOGIC' => 'OR', array('CREATED_BY' => $userId), array('UPDATED_BY' => $userId))), 'order' => array('UPDATE_TIME' => 'DESC'), 'limit' => RecentlyUsedTable::MAX_COUNT_FOR_USER)); while ($row = $query->fetch()) { $objects[] = array('USER_ID' => $userId, 'OBJECT_ID' => $row['ID'], 'CREATE_TIME' => $row['UPDATE_TIME']); } unset($row, $query, $fromDate); Collection::sortByColumn($objects, array('CREATE_TIME' => SORT_ASC)); RecentlyUsedTable::insertBatch($objects); return true; }
protected function refreshTrackingStatusAction() { $shipmentId = !empty($this->request["shipmentId"]) && intval($this->request["shipmentId"]) > 0 ? intval($this->request["shipmentId"]) : 0; $trackingNumber = !empty($this->request["trackingNumber"]) && strlen($this->request["trackingNumber"]) > 0 ? $this->request["trackingNumber"] : ''; if ($shipmentId <= 0) { throw new ArgumentNullException('shipmentId'); } $manager = Sale\Delivery\Tracking\Manager::getInstance(); $result = $manager->getStatusByShipmentId($shipmentId, $trackingNumber); if ($result->isSuccess()) { $this->addResultData('TRACKING_STATUS', Sale\Delivery\Tracking\Manager::getStatusName($result->status)); $this->addResultData('TRACKING_DESCRIPTION', $result->description); $this->addResultData('TRACKING_LAST_CHANGE', \Bitrix\Main\Type\DateTime::createFromTimestamp($result->lastChangeTimestamp)->toString()); $res = $manager->updateShipment($shipmentId, $result); if (!$res->isSuccess()) { $this->addResultError(implode(", ", $res->getErrorMessages())); } } else { $this->addResultError(implode("\n", $result->getErrorMessages())); } }
function InstallDB() { global $DB, $APPLICATION; global $stackCacheManager; global $CACHE_MANAGER; $this->errors = false; $bitrix24Path = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/bitrix24/'; $bitrix24 = file_exists($bitrix24Path) && is_dir($bitrix24Path); unset($bitrix24Path); if (!$DB->Query("SELECT COUNT(CURRENCY) FROM b_catalog_currency", true)): $this->errors = $DB->RunSQLBatch($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/currency/install/db/".strtolower($DB->type)."/install.sql"); endif; if ($this->errors !== false) { $APPLICATION->ThrowException(implode("", $this->errors)); return false; } RegisterModule("currency"); $stackCacheManager->Clear("currency_currency_lang"); $CACHE_MANAGER->Clean("currency_currency_list", 'b_catalog_currency'); $CACHE_MANAGER->Clean("currency_base_currency", 'b_catalog_currency'); $stackCacheManager->Clear("currency_rate"); if (Loader::includeModule("currency")) { $currencyIterator = CurrencyTable::getList(array( 'select' => array('CURRENCY'), 'limit' => 1 )); if (!($currency = $currencyIterator->fetch())) { $languageID = ''; $siteIterator = SiteTable::getList(array( 'select' => array('LID', 'LANGUAGE_ID'), 'filter' => array('DEF' => 'Y', 'ACTIVE' => 'Y') )); if ($site = $siteIterator->fetch()) { $languageID = (string)$site['LANGUAGE_ID']; } if (isset($site)) unset($site); unset($siteIterator); if ($languageID == '') $languageID = 'en'; $currencyList = array(); $currencySetID = ''; switch ($languageID) { case 'ua': case 'de': case 'en': $currencySetID = $languageID; break; case 'ru': if (!$bitrix24) { $languageIterator = LanguageTable::getList(array( 'select' => array('ID'), 'filter' => array('ID' => 'kz', 'ACTIVE' => 'Y') )); if ($existLanguage = $languageIterator->fetch()) { $currencySetID = $existLanguage['ID']; } if ($currencySetID == '') { $languageIterator = LanguageTable::getList(array( 'select' => array('ID'), 'filter' => array('ID' => 'ua', 'ACTIVE' => 'Y') )); if ($existLanguage = $languageIterator->fetch()) { $currencySetID = $existLanguage['ID']; } } } if ($currencySetID == '') { $currencySetID = $languageID; } break; default: $currencySetID = 'en'; break; } $datetimeEntity = new SqlExpression(Application::getConnection()->getSqlHelper()->getCurrentDateTimeFunction()); switch ($currencySetID) { case 'kz': $addCurrency = array( array('CURRENCY' => 'KZT', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'RUB', 'AMOUNT' => 1, 'AMOUNT_CNT' => 4.72, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 4.72), array('CURRENCY' => 'USD', 'AMOUNT' => 1, 'AMOUNT_CNT' => 154.52, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 154.52), array('CURRENCY' => 'EUR', 'AMOUNT' => 1, 'AMOUNT_CNT' => 212.73, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 212.73) ); break; case 'ua': $addCurrency = array( array('CURRENCY' => 'UAH', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'RUB', 'AMOUNT' => 2.54, 'AMOUNT_CNT' => 10, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.254), array('CURRENCY' => 'USD', 'AMOUNT' => 799.3, 'AMOUNT_CNT' => 100, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 7.993), array('CURRENCY' => 'EUR', 'AMOUNT' => 1083.37, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 10.8337) ); break; case 'ru': $addCurrency = array( array('CURRENCY' => 'RUB', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'AMOUNT' => 32.30, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 32.30), array('CURRENCY' => 'EUR', 'AMOUNT' => 43.80, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 43.80), array('CURRENCY' => 'UAH', 'AMOUNT' => 39.41, 'AMOUNT_CNT' => 10, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 3.941), array('CURRENCY' => 'BYR', 'AMOUNT' => 36.72, 'AMOUNT_CNT' => 10000, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.003672) ); break; case 'de': $addCurrency = array( array('CURRENCY' => 'EUR', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'AMOUNT' => 0.74, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.74) ); break; default: case 'en': $addCurrency = array( array('CURRENCY' => 'USD', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'EUR', 'AMOUNT' => 1.36, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 1.36) ); break; } foreach ($addCurrency as &$fields) { $fields['CREATED_BY'] = null; $fields['MODIFIED_BY'] = null; $fields['DATE_CREATE'] = $datetimeEntity; $fields['DATE_UPDATE'] = $datetimeEntity; $currencyResult = CurrencyTable::add($fields); if ($currencyResult->isSuccess()) $currencyList[] = $fields['CURRENCY']; } unset($currencyResult, $fields); if (!empty($currencyList)) { Option::set('currency', 'installed_currencies', implode(',', $currencyList), ''); $languageIterator = LanguageTable::getList(array( 'select' => array('ID'), 'filter' => array('ACTIVE' => 'Y') )); while ($existLanguage = $languageIterator->fetch()) { $CACHE_MANAGER->Clean('currency_currency_list_'.$existLanguage['ID']); $messList = Loc::loadLanguageFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/currency/install_lang.php', $existLanguage['ID']); foreach($currencyList as &$oneCurrency) { $fields = array( 'LID' => $existLanguage['ID'], 'CURRENCY' => $oneCurrency, 'THOUSANDS_SEP' => false, 'DECIMALS' => 2, 'HIDE_ZERO' => 'Y', 'FORMAT_STRING' => $messList['CUR_INSTALL_'.$oneCurrency.'_FORMAT_STRING'], 'FULL_NAME' => $messList['CUR_INSTALL_'.$oneCurrency.'_FULL_NAME'], 'DEC_POINT' => $messList['CUR_INSTALL_'.$oneCurrency.'_DEC_POINT'], 'THOUSANDS_VARIANT' => $messList['CUR_INSTALL_'.$oneCurrency.'_THOUSANDS_SEP'], 'CREATED_BY' => null, 'MODIFIED_BY' => null, 'DATE_CREATE' => $datetimeEntity, 'TIMESTAMP_X' => $datetimeEntity ); $resultCurrencyLang = CurrencyLangTable::add($fields); } unset($oneCurrency); } unset($existLanguage, $languageIterator); if (!$bitrix24) { $checkDate = DateTime::createFromTimestamp(strtotime('tomorrow 00:01:00'));; CAgent::AddAgent('\Bitrix\Currency\CurrencyTable::currencyBaseRateAgent();', 'currency', 'Y', 86400, '', 'Y', $checkDate->toString(), 100, false, true); } } } } $stackCacheManager->Clear("currency_currency_lang"); $CACHE_MANAGER->Clean("currency_currency_list", 'b_catalog_currency'); $CACHE_MANAGER->Clean("currency_base_currency", 'b_catalog_currency'); $stackCacheManager->Clear("currency_rate"); return true; }
public static function updateAgent() { $engine = new self(); if ($engine->getAuthSettings()) { try { $dbRes = YandexCampaignTable::getList(array('filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexCampaignTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId()), 'select' => array('CNT'), 'runtime' => array(new ExpressionField('CNT', 'COUNT(*)')))); $res = $dbRes->fetch(); if ($res['CNT'] > 0) { $engine->updateCampaignManual(); } $availableCampaigns = array(); $campaignList = $engine->getCampaignList(); foreach ($campaignList as $campaignInfo) { $availableCampaigns[] = $campaignInfo['CampaignID']; } if (count($availableCampaigns) > 0) { $dbRes = YandexBannerTable::getList(array('group' => array('CAMPAIGN_ID'), 'filter' => array('<LAST_UPDATE' => DateTime::createFromTimestamp(time() - YandexBannerTable::CACHE_LIFETIME), '=ENGINE_ID' => $engine->getId(), '=CAMPAIGN.XML_ID' => $availableCampaigns), 'select' => array('CAMPAIGN_ID'))); $campaignId = array(); while ($res = $dbRes->fetch()) { $campaignId[] = $res['CAMPAIGN_ID']; } if (count($campaignId) > 0) { $engine->updateBannersManual($campaignId); } } } catch (YandexDirectException $e) { } } return __CLASS__ . "::updateAgent();"; }
/** * @param $name * @param $targetElementId * @param TmpFile $tmpFile * @param array $data * @return array|bool * @throws AccessDeniedException */ public function updateFile($name, $targetElementId, TmpFile $tmpFile, array $data = array()) { /** @var File $file */ $file = File::loadById($targetElementId); if (!$file) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$targetElementId}", 11154))); $tmpFile->delete(); return false; } if (!$file->canUpdate($this->storage->getCurrentUserSecurityContext())) { $tmpFile->delete(); throw new AccessDeniedException(); } /** @var array $fileArray */ if ($tmpFile->isCloud() && $tmpFile->getContentType()) { /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $fileId = \CFile::saveFile(array('name' => $tmpFile->getFilename(), 'tmp_name' => $tmpFile->getAbsolutePath(), 'type' => $tmpFile->getContentType()), Driver::INTERNAL_MODULE_ID, true, true); /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $fileArray = \CFile::getFileArray($fileId); if (!$fileArray) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " getFileArray", 1115541))); $tmpFile->delete(); return false; } if (!empty($data['originalTimestamp'])) { $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp'])); } if ($file->addVersion($fileArray, $this->getUser()->getId())) { $tmpFile->delete(); $this->loadFormattedFolderTreeAndBreadcrumbs(); return $this->formatFileToResponse($file); } else { \CFile::delete($fileId); } } else { $fileArray = \CFile::makeFileArray($tmpFile->getAbsolutePath()); if (!$fileArray) { $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " MakeFileArray", 11155))); $tmpFile->delete(); return false; } if (!empty($data['originalTimestamp'])) { $fileArray['UPDATE_TIME'] = DateTime::createFromTimestamp($this->convertFromExternalVersion($data['originalTimestamp'])); } if ($file->uploadVersion($fileArray, $this->getUser()->getId())) { $tmpFile->delete(); $this->loadFormattedFolderTreeAndBreadcrumbs(); return $this->formatFileToResponse($file); } } $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", uploadVersion", 11156))); $this->errorCollection->add($file->getErrors()); $tmpFile->delete(); return false; }
protected function sendDataSftp() { $directory = new \Bitrix\Main\IO\Directory($this->path . "/zip"); if (!$directory->isExists()) { throw new SystemException("Directory" . $this->path . "/zip does not exist! " . __METHOD__); } $filesToSend = $directory->getChildren(); if (empty($filesToSend)) { return false; } $sftp = \Bitrix\Sale\TradingPlatform\Ebay\Helper::getSftp($this->siteId); $sftp->connect(); for ($i = 0; $i < count($filesToSend); $i++) { $directoryEntry = $filesToSend[$i]; $localPath = $directoryEntry->getPath(); if (!$directoryEntry instanceof \Bitrix\Main\IO\File || GetFileExtension($localPath) != "zip") { continue; } $remote = $this->remotePath . "/" . $directoryEntry->getName(); while (!$this->checkOuterConditions($sftp)) { if ($this->timer !== null && !$this->timer->check(15)) { return false; } sleep(10); } if ($sftp->uploadFile($localPath, $remote)) { $directoryEntry->delete(); ResultsTable::add(array("FILENAME" => $directoryEntry->getName(), "FEED_TYPE" => $this->feedType, "UPLOAD_TIME" => DateTime::createFromTimestamp(time()))); Ebay::log(Logger::LOG_LEVEL_INFO, "EBAY_DATA_PROCESSOR_SFTPQUEUE_SEND", $remote, "File sent successfully.", $this->siteId); } } return true; }
/** * @param string $action * @return array */ protected function toView($action = null) { /** @global CMain $APPLICATION */ global $APPLICATION; $error = $this->checkRequirements(); if ($error) { return array('MESSAGE' => $error); } $result = array(); switch ($action) { case 'download': $codes = $this->getRecoveryCodes(true, true); $response = ''; $counter = 0; foreach ($codes as $code) { $counter++; $response .= sprintf("%d. %s\r\n", $counter, $code['VALUE']); } $result['PLAIN_RESPONSE'] = $response; break; case 'print': $result['CODES'] = $this->getRecoveryCodes(true, true); break; case 'view': default: $result['CODES'] = $this->getRecoveryCodes(false, true); break; } $result['ISSUER'] = Option::get('main', 'server_name'); if (!$result['ISSUER']) { $result['ISSUER'] = Option::get('security', 'otp_issuer', 'Bitrix'); } $result['CREATE_DATE'] = CUserOptions::GetOption('security', 'recovery_codes_generated', null); if ($result['CREATE_DATE']) { $result['CREATE_DATE'] = Type\DateTime::createFromTimestamp($result['CREATE_DATE']); } return $result; }
/** * @param int $shipmentId * @param StatusResult $params * @param bool|false $isStatusChanged * @return Result * @throws ArgumentNullException * @throws \Exception */ public function updateShipment($shipmentId, StatusResult $params) { if ($shipmentId <= 0) { throw new ArgumentNullException('id'); } $dateTime = new \Bitrix\Main\Type\DateTime(); return ShipmentTable::update($shipmentId, array('TRACKING_STATUS' => $params->status, 'TRACKING_LAST_CHECK' => $dateTime, 'TRACKING_LAST_CHANGE' => \Bitrix\Main\Type\DateTime::createFromTimestamp($params->lastChangeTimestamp), 'TRACKING_DESCRIPTION' => $params->description, 'TRACKING_NUMBER' => $params->trackingNumber)); }
public function createInvoices(array $params) { $count = isset($params['COUNT']) ? (int) $params['COUNT'] : 0; if ($count <= 0) { return; } $sum = isset($params['SUM']) ? (int) $params['SUM'] : 0; if ($sum <= 0) { return; } $dealID = isset($params['DEAL_ID']) ? (int) $params['DEAL_ID'] : 0; $companyID = isset($params['COMPANY_ID']) ? (int) $params['COMPANY_ID'] : 0; $contactID = isset($params['CONTACT_ID']) ? (int) $params['CONTACT_ID'] : 0; $userIDs = isset($params['USER_IDS']) && is_array($params['USER_IDS']) ? $params['USER_IDS'] : array(); if (empty($userIDs)) { $userIDs[] = \CCrmSecurityHelper::GetCurrentUserID(); } $prefix = isset($params['PREFIX']) ? $params['PREFIX'] : ''; if ($prefix === '') { $prefix = $this->id; } $date = isset($params['DATE']) ? $params['DATE'] : null; if (!$date) { $date = $date = new Date(); } $maxDateOffset = isset($params['MAX_DATE_OFFSET']) ? (int) $params['MAX_DATE_OFFSET'] : 0; $dateFormat = Date::convertFormatToPhp(FORMAT_DATE); $dateTimeFormat = Date::convertFormatToPhp(FORMAT_DATETIME); $isWon = isset($params['IS_WON']) ? $params['IS_WON'] : false; if ($isWon) { $totalSum = $sum; } else { $totalSum = $sum - mt_rand((int) ($sum / 3), $sum); } $entity = new \CCrmInvoice(false); $invoiceSum = (int) $totalSum / $count; $totalInvoiceSum = 0; for ($i = 1; $i <= $count; $i++) { if ($i == $count) { $invoiceSum = $totalSum - $totalInvoiceSum; } $totalInvoiceSum += $invoiceSum; $time = DateTime::createFromTimestamp($date->getTimestamp()); if ($maxDateOffset > 0) { $time->add(mt_rand(0, $maxDateOffset) . ' days'); } $time->setTime(mt_rand(8, 20), mt_rand(0, 59), 0); $siteTime = $time->format($dateTimeFormat); $siteDate = $time->format($dateFormat); \CCrmOwnerType::GetCaption(\CCrmOwnerType::Company, $companyID, false); $companyInfo = self::getCompanyInfo($companyID); $contactInfo = self::getContactInfo($contactID); $fields = array('ORDER_TOPIC' => "{$prefix} invoice # {$i}", 'STATUS_ID' => $isWon ? 'P' : 'N', 'DATE_INSERT' => $siteTime, 'DATE_BILL' => $siteDate, 'RESPONSIBLE_ID' => self::getRandomItem($userIDs), 'UF_DEAL_ID' => $dealID, 'UF_COMPANY_ID' => $companyID, 'UF_CONTACT_ID' => $contactID, 'PERSON_TYPE_ID' => 1, 'PAY_SYSTEM_ID' => 1, 'INVOICE_PROPERTIES' => array(10 => $companyInfo['TITLE'], 11 => $companyInfo['FULL_ADDRESS'], 12 => $contactInfo['FULL_NAME'], 13 => $contactInfo['EMAIL'], 14 => $contactInfo['PHONE']), 'PRODUCT_ROWS' => array(array('ID' => 0, 'PRODUCT_NAME' => "{$prefix} product", 'QUANTITY' => 1, 'PRICE' => $invoiceSum, 'PRODUCT_ID' => 0, 'CUSTOMIZED' => 'Y'))); $ID = $entity->Add($fields); } }
$fromDate = new Type\DateTime($arParams['CUSTOM_DAY'] . ' 00:00:00', 'Y-m-d H:i:s'); } catch (\Bitrix\Main\ObjectException $e) { $fromDate = Type\DateTime::createFromTimestamp(mktime(0, 0, 0)); } $toDate = clone $fromDate; $toDate->add('+23 hour 59 minute'); // day, because we need empty records for all users $interval = 'day'; $dateFormat = 'Y-m-d H:00:00'; $axisDateFormat = "H"; $axisCursorDateFormat = "d M Y\n" . (IsAmPmMode() ? "g:i a" : "H:i"); break; default: // for today, from 00:00 till 23:59 $fromDate = Type\DateTime::createFromTimestamp(mktime(0, 0, 0)); $toDate = Type\DateTime::createFromTimestamp(mktime(23, 59, 59)); // day, because we need empty records for all users $interval = 'day'; $dateFormat = 'Y-m-d H:00:00'; $axisDateFormat = "H"; $axisCursorDateFormat = array("today" => "today, " . (IsAmPmMode() ? "g:i a" : "H:i")); } $sectionField = empty($arParams['SECTION']) ? 'TOTAL' : $arParams['SECTION']; $arParams['NON_INVOLVED'] = isset($arParams['NON_INVOLVED']) && $arParams['NON_INVOLVED'] || isset($_REQUEST['LIST']) && $_REQUEST['LIST'] === 'involve'; if (!isset($arParams['OFFSET'])) { $arParams['OFFSET'] = isset($_REQUEST['OFFSET']) ? (int) $_REQUEST['OFFSET'] : 0; } if (!isset($arParams['TOP_ACTIVITY']) && isset($_REQUEST['TOP_ACTIVITY'])) { $arParams['TOP_ACTIVITY'] = $_REQUEST['TOP_ACTIVITY']; } $data = \Bitrix\Intranet\UStat\UStat::getUsersTop(1, 0, $fromDate, $toDate, $interval, $sectionField, $arParams['NON_INVOLVED'], $arParams['OFFSET'], 20);
/** * Overrides parent update to sate update date to current. * @param mixed $primary Primary key. * @param array $data Data fields. * @return Entity\UpdateResult */ public static function update($primary, array $data) { $data["LAST_UPDATE"] = DateTime::createFromTimestamp(time()); return parent::update($primary, $data); }
protected function installCurrencies() { if (!Loader::includeModule('currency')) { return; } $bitrix24Path = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/bitrix24/'; $bitrix24 = file_exists($bitrix24Path) && is_dir($bitrix24Path); unset($bitrix24Path); $currencyIterator = \Bitrix\Currency\CurrencyTable::getList(array('select' => array('CURRENCY'), 'limit' => 1)); $currency = $currencyIterator->fetch(); if (!empty($currency)) { return; } $languageID = ''; $siteIterator = SiteTable::getList(array('select' => array('LID', 'LANGUAGE_ID'), 'filter' => array('=DEF' => 'Y', '=ACTIVE' => 'Y'))); if ($site = $siteIterator->fetch()) { $languageID = (string) $site['LANGUAGE_ID']; } unset($site, $siteIterator); if ($languageID == '') { $languageID = 'en'; } $currencyList = array(); $currencySetID = ''; switch ($languageID) { case 'ua': case 'de': case 'en': case 'la': case 'tc': case 'sc': case 'in': $currencySetID = $languageID; break; case 'ru': if (!$bitrix24) { $languageIterator = LanguageTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => 'kz', '=ACTIVE' => 'Y'))); if ($existLanguage = $languageIterator->fetch()) { $currencySetID = $existLanguage['ID']; } if ($currencySetID == '') { $languageIterator = LanguageTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => 'ua', '=ACTIVE' => 'Y'))); if ($existLanguage = $languageIterator->fetch()) { $currencySetID = $existLanguage['ID']; } } unset($existLanguage, $languageIterator); } if ($currencySetID == '') { $currencySetID = $languageID; } break; default: $currencySetID = 'en'; break; } $datetimeEntity = new Main\DB\SqlExpression(Main\Application::getConnection()->getSqlHelper()->getCurrentDateTimeFunction()); switch ($currencySetID) { case 'kz': $addCurrency = array(array('CURRENCY' => 'KZT', 'NUMCODE' => '398', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'RUB', 'NUMCODE' => '643', 'AMOUNT' => 4.4, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 4.4), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 283.17, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 283.17), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 310.78, 'AMOUNT_CNT' => 1, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 310.78)); break; case 'ua': $addCurrency = array(array('CURRENCY' => 'UAH', 'NUMCODE' => '980', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'RUB', 'NUMCODE' => '643', 'AMOUNT' => 3.61, 'AMOUNT_CNT' => 10, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.361), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 2322.93, 'AMOUNT_CNT' => 100, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 23.2293), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 2548.19, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 25.4819)); break; case 'ru': $addCurrency = array(array('CURRENCY' => 'RUB', 'NUMCODE' => '643', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 64.36, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 64.36), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 70.59999999999999, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 70.59999999999999), array('CURRENCY' => 'UAH', 'NUMCODE' => '980', 'AMOUNT' => 27.69, 'AMOUNT_CNT' => 10, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 2.769), array('CURRENCY' => 'BYR', 'NUMCODE' => '974', 'AMOUNT' => 36.9, 'AMOUNT_CNT' => 10000, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.00369)); break; case 'de': case 'la': $addCurrency = array(array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 0.91, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.91), array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 14.35, 'AMOUNT_CNT' => 100, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.1435), array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 23.21, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.2321), array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 13.97, 'AMOUNT_CNT' => 1000, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.01397)); break; case 'tc': case 'sc': $addCurrency = array(array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 6.36, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 6.36), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 6.97, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 6.97), array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 1.61, 'AMOUNT_CNT' => 1, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 1.61), array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 9.74, 'AMOUNT_CNT' => 100, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.09737)); break; case 'in': $addCurrency = array(array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 65.31, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 65.31), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 71.56, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 71.56), array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 10.27, 'AMOUNT_CNT' => 1, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 10.27), array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 16.56, 'AMOUNT_CNT' => 1, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 16.56)); break; case 'br': $addCurrency = array(array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 3.9, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 3.9), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 4.29, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 4.29), array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 61.44, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.6143999999999999), array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 5.99, 'AMOUNT_CNT' => 100, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.0599)); break; default: case 'en': $addCurrency = array(array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 1.1, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 1.1), array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 15.73, 'AMOUNT_CNT' => 100, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.1573), array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 25.35, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.2535), array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 15.31, 'AMOUNT_CNT' => 1000, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.01531)); break; } foreach ($addCurrency as &$fields) { $fields['CREATED_BY'] = null; $fields['MODIFIED_BY'] = null; $fields['DATE_CREATE'] = $datetimeEntity; $fields['DATE_UPDATE'] = $datetimeEntity; $currencyResult = \Bitrix\Currency\CurrencyTable::add($fields); if ($currencyResult->isSuccess()) { $currencyList[] = $fields['CURRENCY']; } } unset($currencyResult, $fields); if (!empty($currencyList)) { Option::set('currency', 'installed_currencies', implode(',', $currencyList), ''); $languageIterator = LanguageTable::getList(array('select' => array('ID'), 'filter' => array('=ACTIVE' => 'Y'))); while ($existLanguage = $languageIterator->fetch()) { $messList = Loc::loadLanguageFile($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/currency/install_lang.php', $existLanguage['ID']); foreach ($currencyList as &$oneCurrency) { $fields = array('LID' => $existLanguage['ID'], 'CURRENCY' => $oneCurrency, 'THOUSANDS_SEP' => false, 'DECIMALS' => 2, 'HIDE_ZERO' => 'Y', 'FORMAT_STRING' => $messList['CUR_INSTALL_' . $oneCurrency . '_FORMAT_STRING'], 'FULL_NAME' => $messList['CUR_INSTALL_' . $oneCurrency . '_FULL_NAME'], 'DEC_POINT' => $messList['CUR_INSTALL_' . $oneCurrency . '_DEC_POINT'], 'THOUSANDS_VARIANT' => $messList['CUR_INSTALL_' . $oneCurrency . '_THOUSANDS_SEP'], 'CREATED_BY' => null, 'MODIFIED_BY' => null, 'DATE_CREATE' => $datetimeEntity, 'TIMESTAMP_X' => $datetimeEntity); $resultCurrencyLang = \Bitrix\Currency\CurrencyLangTable::add($fields); unset($resultCurrencyLang); } unset($oneCurrency, $messList); } unset($existLanguage, $languageIterator); if (!$bitrix24) { $checkDate = Main\Type\DateTime::createFromTimestamp(strtotime('tomorrow 00:01:00')); CAgent::AddAgent('\\Bitrix\\Currency\\CurrencyTable::currencyBaseRateAgent();', 'currency', 'Y', 86400, '', 'Y', $checkDate->toString(), 100, false, true); unset($checkDate); } \Bitrix\Currency\CurrencyManager::clearCurrencyCache(); } unset($datetimeEntity); }
protected function processActionSaveSettingsExternalLink() { /** @var File $file */ /** @var ExternalLink $extLink */ list($file, $extLink) = $this->getFileAndExternalLink(); if (!$extLink) { $this->sendJsonErrorResponse(); } if ($this->request->getPost('deathTime')) { $extLink->changeDeathTime(DateTime::createFromTimestamp(time() + (int) $this->request->getPost('deathTime'))); } if ($this->request->getPost('password')) { $extLink->changePassword($this->request->getPost('password')); } $this->sendJsonSuccessResponse(array('object' => array('name' => $file->getName(), 'size' => \CFile::formatSize($file->getSize()), 'date' => (string) $file->getUpdateTime()), 'linkData' => array('hasPassword' => $extLink->hasPassword(), 'hasDeathTime' => $extLink->hasDeathTime(), 'hash' => $extLink->getHash(), 'link' => Driver::getInstance()->getUrlManager()->getShortUrlExternalLink(array('hash' => $extLink->getHash(), 'action' => 'default'), true)))); }
protected function installCurrencies() { if (!Loader::includeModule('currency')) return; $bitrix24Path = $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/bitrix24/'; $bitrix24 = file_exists($bitrix24Path) && is_dir($bitrix24Path); unset($bitrix24Path); $currencyIterator = \Bitrix\Currency\CurrencyTable::getList(array( 'select' => array('CURRENCY'), 'limit' => 1 )); $currency = $currencyIterator->fetch(); if (!empty($currency)) return; $languageID = ''; $siteIterator = SiteTable::getList(array( 'select' => array('LID', 'LANGUAGE_ID'), 'filter' => array('=DEF' => 'Y', '=ACTIVE' => 'Y') )); if ($site = $siteIterator->fetch()) $languageID = (string)$site['LANGUAGE_ID']; unset($site, $siteIterator); if ($languageID == '') $languageID = 'en'; $currencyList = array(); $currencySetID = ''; switch ($languageID) { case 'ua': case 'de': case 'en': case 'la': case 'tc': case 'sc': $currencySetID = $languageID; break; case 'ru': if (!$bitrix24) { $languageIterator = LanguageTable::getList(array( 'select' => array('ID'), 'filter' => array('=ID' => 'kz', '=ACTIVE' => 'Y') )); if ($existLanguage = $languageIterator->fetch()) $currencySetID = $existLanguage['ID']; if ($currencySetID == '') { $languageIterator = LanguageTable::getList(array( 'select' => array('ID'), 'filter' => array('=ID' => 'ua', '=ACTIVE' => 'Y') )); if ($existLanguage = $languageIterator->fetch()) $currencySetID = $existLanguage['ID']; } unset($existLanguage, $languageIterator); } if ($currencySetID == '') $currencySetID = $languageID; break; default: $currencySetID = 'en'; break; } $datetimeEntity = new Main\DB\SqlExpression(Main\Application::getConnection()->getSqlHelper()->getCurrentDateTimeFunction()); switch ($currencySetID) { case 'kz': $addCurrency = array( array('CURRENCY' => 'KZT', 'NUMCODE' => '398', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'RUB', 'NUMCODE' => '643', 'AMOUNT' => 1, 'AMOUNT_CNT' => 3.09, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 3.09), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 1, 'AMOUNT_CNT' => 185.5, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 185.5), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 1, 'AMOUNT_CNT' => 198.13, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 198.13) ); break; case 'ua': $addCurrency = array( array('CURRENCY' => 'UAH', 'NUMCODE' => '980', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'RUB', 'NUMCODE' => '643', 'AMOUNT' => 4.00, 'AMOUNT_CNT' => 10, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.4), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 2355.70, 'AMOUNT_CNT' => 100, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 23.557), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 2579.49, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 25.7949) ); break; case 'ru': $addCurrency = array( array('CURRENCY' => 'RUB', 'NUMCODE' => '643', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 57.39, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 57.39), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 62.77, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 62.77), array('CURRENCY' => 'UAH', 'NUMCODE' => '980', 'AMOUNT' => 24.53, 'AMOUNT_CNT' => 10, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 2.453), array('CURRENCY' => 'BYR', 'NUMCODE' => '974', 'AMOUNT' => 39.44, 'AMOUNT_CNT' => 10000, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.003944) ); break; case 'de': case 'la': $addCurrency = array( array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 0.91, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.91), array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 14.65, 'AMOUNT_CNT' => 100, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.1465), array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 29.12, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.2912), array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 14.59, 'AMOUNT_CNT' => 1000, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.01459) ); break; case 'tc': case 'sc': $addCurrency = array( array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 6.21, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.1610), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 6.75, 'AMOUNT_CNT' => 1, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.1482), array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 1.93, 'AMOUNT_CNT' => 1, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.5181), array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 9,94, 'AMOUNT_CNT' => 100, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.0994) ); break; default: case 'en': $addCurrency = array( array('CURRENCY' => 'USD', 'NUMCODE' => '840', 'AMOUNT' => 1, 'AMOUNT_CNT' => 1, 'SORT' => 100, 'BASE' => 'Y', 'CURRENT_BASE_RATE' => 1), array('CURRENCY' => 'EUR', 'NUMCODE' => '978', 'AMOUNT' => 1.09, 'AMOUNT_CNT' => 1, 'SORT' => 200, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 1.09), array('CURRENCY' => 'CNY', 'NUMCODE' => '156', 'AMOUNT' => 16.09, 'AMOUNT_CNT' => 100, 'SORT' => 300, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.1609), array('CURRENCY' => 'BRL', 'NUMCODE' => '986', 'AMOUNT' => 31.24, 'AMOUNT_CNT' => 100, 'SORT' => 400, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.3124), array('CURRENCY' => 'INR', 'NUMCODE' => '356', 'AMOUNT' => 16.02, 'AMOUNT_CNT' => 1000, 'SORT' => 500, 'BASE' => 'N', 'CURRENT_BASE_RATE' => 0.01602) ); break; } foreach ($addCurrency as &$fields) { $fields['CREATED_BY'] = null; $fields['MODIFIED_BY'] = null; $fields['DATE_CREATE'] = $datetimeEntity; $fields['DATE_UPDATE'] = $datetimeEntity; $currencyResult = \Bitrix\Currency\CurrencyTable::add($fields); if ($currencyResult->isSuccess()) $currencyList[] = $fields['CURRENCY']; } unset($currencyResult, $fields); if (!empty($currencyList)) { Option::set('currency', 'installed_currencies', implode(',', $currencyList), ''); $languageIterator = LanguageTable::getList(array( 'select' => array('ID'), 'filter' => array('=ACTIVE' => 'Y') )); while ($existLanguage = $languageIterator->fetch()) { $messList = Loc::loadLanguageFile($_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/currency/install_lang.php', $existLanguage['ID']); foreach($currencyList as &$oneCurrency) { $fields = array( 'LID' => $existLanguage['ID'], 'CURRENCY' => $oneCurrency, 'THOUSANDS_SEP' => false, 'DECIMALS' => 2, 'HIDE_ZERO' => 'Y', 'FORMAT_STRING' => $messList['CUR_INSTALL_'.$oneCurrency.'_FORMAT_STRING'], 'FULL_NAME' => $messList['CUR_INSTALL_'.$oneCurrency.'_FULL_NAME'], 'DEC_POINT' => $messList['CUR_INSTALL_'.$oneCurrency.'_DEC_POINT'], 'THOUSANDS_VARIANT' => $messList['CUR_INSTALL_'.$oneCurrency.'_THOUSANDS_SEP'], 'CREATED_BY' => null, 'MODIFIED_BY' => null, 'DATE_CREATE' => $datetimeEntity, 'TIMESTAMP_X' => $datetimeEntity ); $resultCurrencyLang = \Bitrix\Currency\CurrencyLangTable::add($fields); unset($resultCurrencyLang); } unset($oneCurrency, $messList); } unset($existLanguage, $languageIterator); if (!$bitrix24) { $checkDate = Main\Type\DateTime::createFromTimestamp(strtotime('tomorrow 00:01:00'));; CAgent::AddAgent('\Bitrix\Currency\CurrencyTable::currencyBaseRateAgent();', 'currency', 'Y', 86400, '', 'Y', $checkDate->toString(), 100, false, true); unset($checkDate); } \Bitrix\Currency\CurrencyManager::clearCurrencyCache(); } unset($datetimeEntity); }
protected function prepareDataFromOldExtLink(array $extLinkRow) { $extLinkData = array('OBJECT_ID' => !empty($extLinkRow['DISK_ID']) ? $extLinkRow['DISK_ID'] : null, 'CREATED_BY' => $extLinkRow['USER_ID'], 'HASH' => substr($extLinkRow['HASH'], 0, 32), 'DESCRIPTION' => $extLinkRow['DESCRIPTION'], 'DOWNLOAD_COUNT' => $extLinkRow['DOWNLOAD_COUNT'], 'TYPE' => ExternalLinkTable::TYPE_MANUAL, 'CREATE_TIME' => DateTime::createFromTimestamp($extLinkRow['CREATION_DATE'])); //157680000 = 5*365*24*60*60 if ($extLinkRow['LIFETIME'] - time() < 157680000) { //limited life $extLinkData['DEATH_TIME'] = DateTime::createFromTimestamp($extLinkRow['LIFETIME']); } if (!empty($extLinkRow['PASSWORD']) && !empty($extLinkRow['SALT'])) { $extLinkData['PASSWORD'] = $extLinkRow['PASSWORD']; $extLinkData['SALT'] = $extLinkRow['SALT']; return $extLinkData; } return $extLinkData; }
protected function getDeletedElements($version) { $deletedItems = array(); if ($version <= 0) { return array(); } $q = \Bitrix\Disk\Internals\DeletedLogTable::getList(array('filter' => array('STORAGE_ID' => $this->storage->getId(), '>=CREATE_TIME' => DateTime::createFromTimestamp($version)), 'order' => array('CREATE_TIME' => 'DESC'))); while ($row = $q->fetch()) { if (!$row) { continue; } $deletedItems[] = array('id' => $this->generateId(array('FILE' => $row['TYPE'] == ObjectTable::TYPE_FILE, 'ID' => $row['OBJECT_ID'])), 'isDirectory' => $row['TYPE'] == ObjectTable::TYPE_FOLDER, 'deletedBy' => (string) (isset($row['USER_ID']) ? $row['USER_ID'] : 0), 'isDeleted' => true, 'storageId' => $this->getStringStorageId(), 'version' => CWebDavDiskDispatcher::convertToExternalVersion($row['CREATE_TIME']->getTimestamp())); } return $deletedItems; }
public static function getStatusInformation() { // 1. activity score: emulate last 60 minutes $currentActivity = static::getCurrentActivity(); // 2. involvement: last 24 hours // SELECT COUNT(1) AS `INVOLVED_COUNT` FROM (SELECT CASE WHEN // (CASE WHEN SUM(TASKS) > 0 THEN 1 ELSE 0 END + CASE WHEN SUM(CRM) > 0 THEN 1 ELSE 0 END + ...) >= 4 // THEN 1 ELSE 0 END) AS INVOLVED FROM ... GROUP BY USER_ID) // WHERE INVOLVED = 1 $fromDate = Type\DateTime::createFromTimestamp(mktime(0, 0, 0)); $toDate = Type\DateTime::createFromTimestamp(mktime(24, 0, 0)); $currentInvolvement = static::getDepartmentSummaryInvolvement(0, $fromDate, $toDate, 'hour'); /* $names = UserHourTable::getSectionNames(); $fieldExpressions = array_fill(0, count($names), 'CASE WHEN SUM(%s) > 0 THEN 1 ELSE 0 END'); // user involved if used 4 or more services for last 24 hours $involvedExpression = sprintf('CASE WHEN (%s) >= %d THEN 1 ELSE 0 END', join (' + ', $fieldExpressions), static::INVOLVEMENT_SERVICE_COUNT ); // subquery $queryByUser = new Entity\Query(UserHourTable::getEntity()); $queryByUser->setSelect(array( 'USER_ID', 'INVOLVED' => array( 'data_type' => 'integer', 'expression' => array_merge(array($involvedExpression), $names) ))) ->setFilter(array( '><HOUR' => array( ConvertTimeStamp(mktime(date('G'), 0, 0, date('n'), date('j')-1), 'FULL'), // prev day, same hour ConvertTimeStamp(time(), 'FULL') ) )) ->setGroup('USER_ID'); // main query $query = new Entity\Query($queryByUser); $query->setSelect(array( 'INVOLVED_COUNT' => array( 'data_type' => 'integer', 'expression' => array('COUNT(1)') ))) ->setFilter(array('=INVOLVED' => 1)); $data = $query->exec()->fetch(); $currentInvolvement = (int) $data['INVOLVED_COUNT']; */ /* // 3. total employees $usersDepartments = static::getUsersDepartments(); $currentTotalUsers = count($usersDepartments); // 4. online employees $result = Main\UserTable::getList(array( 'select' => array('ONLINE_COUNT' => array( 'data_type' => 'integer', 'expression' => array('COUNT(1)') )), 'filter' => array('=IS_ONLINE' => true) )); $data = $result->fetch(); $currentUsersOnline = (int) $data['ONLINE_COUNT']; // 5. absentees $currentUsersAbsent = 0; $allUsers = array_keys($usersDepartments); $allAbsenceData = \CIntranetUtils::getAbsenceData(array( 'DATE_START' => ConvertTimeStamp(mktime(0, 0, 0), 'FULL'), // current day start 'DATE_FINISH' => ConvertTimeStamp(mktime(23, 59, 59), 'FULL'), // current day end 'PER_USER' => true )); foreach ($allUsers as $userId) { if (isset($allAbsenceData[$userId]) && static::checkTodayAbsence($allAbsenceData[$userId])) { ++$currentUsersAbsent; } } */ // done! return array('ACTIVITY' => $currentActivity, 'INVOLVEMENT' => $currentInvolvement); }
public static function initCurrencyBaseRateAgent() { if (!ModuleManager::isModuleInstalled('bitrix24')) { $agentIterator = CAgent::GetList(array(), array('MODULE_ID' => 'currency', '=NAME' => '\\Bitrix\\Currency\\CurrencyManager::currencyBaseRateAgent();')); if ($agentIterator) { if (!($currencyAgent = $agentIterator->Fetch())) { Currency\CurrencyManager::updateBaseRates(); $checkDate = Main\Type\DateTime::createFromTimestamp(strtotime('tomorrow 00:01:00')); CAgent::AddAgent('\\Bitrix\\Currency\\CurrencyManager::currencyBaseRateAgent();', 'currency', 'Y', 86400, '', 'Y', $checkDate->toString(), 100, false, true); } } } return ''; }
ksort($params); $check = base64_encode(sha1($key, implode("|", array_values($params)))); if ($check != $_SERVER['HTTP_X_API_SIGNATURE']) { qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_AUTH); } } else { qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_AUTH); } } list($orderId, $paymentId) = explode(':', $_POST['bill_id']); /** @var \Bitrix\Sale\Order $order */ $order = Order::load($orderId); if ($order) { $arOrder = $order->getFieldValues(); $payment = $order->getPaymentCollection()->getItemById($paymentId); $paidInfo = array("PS_STATUS" => $_POST['status'] == "paid" ? "Y" : "N", "PS_STATUS_CODE" => substr($_POST['status'], 0, 5), "PS_STATUS_MESSAGE" => Loc::getMessage("SALE_QWH_STATUS_MESSAGE_" . strtoupper($_POST['status'])), "PS_RESPONSE_DATE" => \Bitrix\Main\Type\DateTime::createFromTimestamp(time()), "PS_SUM" => (double) $_POST['amount'], "PS_CURRENCY" => $_POST['ccy'], "PS_STATUS_DESCRIPTION" => ""); if ((int) $_POST['error']) { $paidInfo['PS_STATUS_DESCRIPTION'] = "Error: " . Loc::getMessage("SALE_QWH_ERROR_CODE_" . $_POST['error']); $payment->setFields($paidInfo); qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_OTHER); } foreach ($_POST as $key => $value) { $paidInfo['PS_STATUS_DESCRIPTION'] .= "{$key}:{$value}, "; } $payment->setFields($paidInfo); $changeStatusPay = CSalePaySystemAction::GetParamValue("CHANGE_STATUS_PAY") == "Y"; if ($_POST['status'] == "paid" && $changeStatusPay) { $resPayment = $payment->setField('PAID', 'Y'); if ($resPayment->isSuccess()) { qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_NONE); }
case 'custom_day': // for today, from 00:00 till 23:59 $arParams['CUSTOM_DAY'] = isset($arParams['CUSTOM_DAY']) ? $arParams['CUSTOM_DAY'] : $_REQUEST['CUSTOM_DAY']; $fromDate = new Type\DateTime($arParams['CUSTOM_DAY'] . ' 00:00:00', 'Y-m-d H:i:s'); $fromDate->add('-1 hour'); $toDate = clone $fromDate; $toDate->add('+25 hour'); $interval = 'hour'; $dateFormat = 'Y-m-d H:00:00'; $axisDateFormat = "H"; $axisCursorDateFormat = "d M Y\n" . (IsAmPmMode() ? "g:i a" : "H:i"); break; default: // for today, from 00:00 till 23:59 $fromDate = Type\DateTime::createFromTimestamp(mktime(-1, 0, 0)); $toDate = Type\DateTime::createFromTimestamp(mktime(24, 0, 0)); $interval = 'hour'; $dateFormat = 'Y-m-d H:00:00'; $axisDateFormat = "H"; $axisCursorDateFormat = array("today" => "today, " . (IsAmPmMode() ? "g:i a" : "H:i")); } $fromDateServer = clone $fromDate; $toDateServer = clone $toDate; if ($interval == 'hour') { // with timezones $userTimeOffset = CTimeZone::GetOffset(); $fromUserTimeInterval = -$userTimeOffset . ' seconds'; $fromDateServer->add($fromUserTimeInterval); $toDateServer->add($fromUserTimeInterval); } if (empty($arParams['USER_ID'])) {
ksort($params); $check = base64_encode(sha1($key, implode("|", array_values($params)))); if($check != $_SERVER['HTTP_X_API_SIGNATURE']) qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_AUTH); } else qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_AUTH); } if($order = CSaleOrder::getById($_POST['bill_id'])) { $paidInfo = array( "PS_STATUS" => $_POST['status'] == "paid" ? "Y" : "N", "PS_STATUS_CODE" => substr($_POST['status'], 0, 5), "PS_STATUS_MESSAGE" => Loc::getMessage("SALE_QWH_STATUS_MESSAGE_" . strtoupper($_POST['status'])), "PS_RESPONSE_DATE" => \Bitrix\Main\Type\DateTime::createFromTimestamp(time()), "PS_SUM" => (double)$_POST['amount'], "PS_CURRENCY" => $_POST['ccy'], "PS_STATUS_DESCRIPTION" => "" ); if((int)$_POST['error']) { $paidInfo['PS_STATUS_DESCRIPTION'] = "Error: " . Loc::getMessage("SALE_QWH_ERROR_CODE_" . $_POST['error']); CSaleOrder::Update($order['ID'], $paidInfo); qiwiWalletXmlResponse(QIWI_WALLET_ERROR_CODE_OTHER); } foreach($_POST as $key => $value) $paidInfo['PS_STATUS_DESCRIPTION'] .= "{$key}:{$value}, "; CSaleOrder::Update($order['ID'], $paidInfo);
CCurrency::updateAllCurrencyBaseRate(); LocalRedirect($APPLICATION->GetCurPage() . '?lang=' . LANGUAGE_ID . '&mid=' . $module_id . '&' . $systemTabControl->ActiveTabParam()); } if (isset($_POST['agents']) && $_POST['agents'] == 'Y' && isset($_POST['action']) && !empty($_POST['action'])) { $action = (string) $_POST['action']; switch ($action) { case 'activate': case 'deactivate': $agentIterator = CAgent::GetList(array(), array('MODULE_ID' => 'currency', '=NAME' => '\\Bitrix\\Currency\\CurrencyTable::currencyBaseRateAgent();')); if ($currencyAgent = $agentIterator->Fetch()) { $active = $action == 'activate' ? 'Y' : 'N'; CAgent::Update($currencyAgent['ID'], array('ACTIVE' => $active)); } break; case 'create': $checkDate = DateTime::createFromTimestamp(strtotime('tomorrow 00:01:00')); CAgent::AddAgent('\\Bitrix\\Currency\\CurrencyTable::currencyBaseRateAgent();', 'currency', 'Y', 86400, '', 'Y', $checkDate->toString(), 100, false, true); break; } LocalRedirect($APPLICATION->GetCurPage() . '?lang=' . LANGUAGE_ID . '&mid=' . $module_id . '&' . $systemTabControl->ActiveTabParam()); } } $baseCurrency = Currency\CurrencyManager::getBaseCurrency(); $tabControl->Begin(); ?> <form method="POST" action="<?php echo $APPLICATION->GetCurPage(); ?> ?lang=<?php echo LANGUAGE_ID; ?>
/** * Defer mandatory user OTP using for a needed number of days or forever * * @param int $days Days. 0 means "forever". * @return $this * @throws OtpException */ public function defer($days = 0) { if ($this->isActivated()) { throw new OtpException('Otp already activated. Do your mean deactivate?'); } $this->setSkipMandatory(true); if ($days <= 0) { $this->setDeactivateUntil(null); } else { $deactivateDate = Type\DateTime::createFromTimestamp(time() + $days * 86400); $this->setDeactivateUntil($deactivateDate); } $this->save(); return $this; }
/** * Ping from the agent to inform that it still works correctly. Use this method if your agent * works more 10 minutes, otherwise Bitrix will be consider your agent as non-working. * * Usage: * ```php * public function executeAgent($param1, $param2) * { * // start a heavy (big) cycle * * $this->pingAgent(20, ['executeAgent => [$param1, $param2]]); * * // end of cycle * } * ``` * * @param int $interval The time in minutes after which the agent will be considered non-working. * @param array $callChain Array with the call any methods from Agent class. */ protected function pingAgent($interval, array $callChain) { if (!$this->isAgentMode()) { return; } $name = $this->getAgentName($callChain); $model = new \CAgent(); $rsAgent = $model->GetList([], ['NAME' => $name]); if ($agent = $rsAgent->Fetch()) { $dateCheck = DateTime::createFromTimestamp(time() + $interval * 60); $pingResult = $model->Update($agent['ID'], ['DATE_CHECK' => $dateCheck->toString()]); if (!$pingResult) { // @todo warning } } else { // @todo warning } }
/** * @param string $action * @return array */ protected function toView($action = null) { /** @global CMain $APPLICATION */ global $APPLICATION; $error = $this->checkRequirements(); if ($error) { return array('MESSAGE' => $error); } $result = array(); switch ($action) { case 'download': $codes = $this->getRecoveryCodes(true, true); $response = ''; $counter = 0; foreach ($codes as $code) { $counter++; $response .= sprintf("%d. %s\r\n", $counter, $code['VALUE']); } $APPLICATION->restartBuffer(); header('Content-Type: text/plain', true); header('Content-Disposition: attachment; filename="recovery_codes.txt"'); header('Content-Transfer-Encoding: binary'); header(sprintf('Content-Length: %d', strlen($response))); echo $response; exit; break; case 'print': $result['CODES'] = $this->getRecoveryCodes(true, true); $this->templatePage = static::PRINT_PAGE; break; case 'view': default: $result['CODES'] = $this->getRecoveryCodes(false, true); $this->templatePage = static::VIEW_PAGE; break; } $result['ISSUER'] = Option::get('main', 'server_name'); if (!$result['ISSUER']) { $result['ISSUER'] = Option::get('security', 'otp_issuer', 'Bitrix'); } $result['CREATE_DATE'] = CUserOptions::GetOption('security', 'recovery_codes_generated', null); if ($result['CREATE_DATE']) { $result['CREATE_DATE'] = Type\DateTime::createFromTimestamp($result['CREATE_DATE']); } return $result; }