Skip to content

Instantly share code, notes, and snippets.

@s2ar
s2ar / JS.checked.number.js
Last active April 19, 2016 05:55
JS. checked number
/*
-9007199254740990 to 9007199254740990
*/
function isInt(n) {
return +n === n && !(n % 1);
}
/*
-128 to 127
@s2ar
s2ar / Bitrix.date.filter.php
Created April 23, 2016 08:15
Битрикс. Фильтр по дате
<?php
if($data1=='y') // Год
$arFilter['>UF_DATE_LAST_APPL']=date($DB->DateFormatToPHP(FORMAT_DATETIME), time()-31536000);
if($data1=='m') // Месяц
$arFilter['>UF_DATE_LAST_APPL']=date($DB->DateFormatToPHP(FORMAT_DATETIME), time()-2678400);
if($data1=='w') // Неделя
$arFilter['>UF_DATE_LAST_APPL']=date($DB->DateFormatToPHP(FORMAT_DATETIME), time()-604800);
@s2ar
s2ar / php. сортировка массива по текстовому полю.php
Last active April 23, 2016 08:17
php. сортировка массива по текстовому полю
<?php
if(!function_exists('cmp')){
function cmp($a, $b) {
return strcasecmp($a['short_name'], $b['short_name']);
}
}
uasort($arResult['OFFER_LEAF'], 'cmp');
@s2ar
s2ar / bitrix.change.user.pass.php
Last active April 23, 2016 08:17
bitrix change user pass
<?php
// Оригинал http://pai-bx.com/wiki/1c-bitrix/2913-perform-actions-only-when-a-confirm-password/
$arUser["PASSWORD"] = $USER->GetParam("PASSWORD_HASH");
$arParams["PASSWORD"] = $_POST['PASSWORD'];
$arParams["NEW_PASSWORD"] = $_POST['NEW_PASSWORD'];
$arParams["NEW_PASSWORD_CONFIRM"] = $_POST['CONFIRM_NEW_PASSWORD'];
if (strlen($arUser["PASSWORD"]) > 32) {
$salt = substr($arUser["PASSWORD"], 0, strlen($arUser["PASSWORD"]) - 32);
@s2ar
s2ar / Bitrix. Сохранить свойство типа Файл.php
Last active April 23, 2016 08:18
Bitrix. Сохранить свойство типа Файл
<?php
$_FILES['appl_file_input']["MODULE_ID"] = "docsapplications";
CIBlockElement::SetPropertyValueCode($id, 'APDOCS_FILE', $_FILES['appl_file_input']);
@s2ar
s2ar / array to xml.php
Last active April 23, 2016 08:21
array to xml
<?php
//function defination to convert array to xml
function array_to_xml($array, &$xml_user_info) {
foreach($array as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml_user_info->addChild("$key");
array_to_xml($value, $subnode);
}else{
$subnode = $xml_user_info->addChild("item$key");
@s2ar
s2ar / bitrix запись в журнал событий.php
Last active April 23, 2016 08:22
bitrix запись в журнал событий
<?php
AddEventHandler('main', 'OnEventLogGetAuditTypes', 'ASD_OnEventLogGetAuditTypes');
function ASD_OnEventLogGetAuditTypes()
{
return array('MY_OWN_TYPE' => '[MY_OWN_TYPE] Мой собственный тип');
}
CEventLog::Add(array(
"SEVERITY" => "SECURITY",
@s2ar
s2ar / bitrix.highload iblock element.php
Last active April 23, 2016 08:23
bitrix.highload iblock element
<?php
use Bitrix\Main\Application;
use Bitrix\Highloadblock\HighloadBlockTable;
use Bitrix\Main\Loader;
Loader::includeModule('highloadblock');
Loader::includeModule('iblock');
$hlBlockId = 2;
@s2ar
s2ar / urlrewrite.php
Last active April 23, 2016 08:23
Bitrix.urlrewrite
<?php
array(
"CONDITION" => "#^/weather/([^/]+)/([^/]+)/($|index\\.php|\\?.*)#",
"RULE" => "COUNTRY_CODE=$1&CITY_CODE=$2",
"ID" => "",
"PATH" => "/weather/city.php",
),
/*
/weather/russia/moscow/ => /weather/city.php?COUNTRY_CODE=russia&CITY_CODE=moscow
@s2ar
s2ar / Bitrix.application.request.php
Last active April 23, 2016 08:24
Bitrix Application Request
<?php
use Bitrix\Main\Application;
$request = Application::getInstance()->getContext()->getRequest();
$value = $request->get("some_name");
$value = $request["some_name"];
$value = $request->getQuery("some_name"); // получение GET-параметра
$value = $request->getPost("some_name"); // получение POST-параметра
$value = $request->getFile("some_name"); // получение загруженного файла