проверка даты на корректность, аля 30.02.2013

15.01.2013 javascript No comments , ,

function checkDay(R_BIRTHDAY_DAY, R_BIRTHDAY_MONTH, R_BIRTHDAY_YEAR){

	if(R_BIRTHDAY_DAY == '' || R_BIRTHDAY_MONTH == '' || R_BIRTHDAY_YEAR == ''){

		return false;
	}
	R_BIRTHDAY_MONTH = R_BIRTHDAY_MONTH - 1; 						
	var thisDate     = new Date(R_BIRTHDAY_YEAR, R_BIRTHDAY_MONTH , R_BIRTHDAY_DAY);
	var dayThis      = thisDate.getDate()
	var monthThis    = thisDate.getMonth()
	var yearThis     = thisDate.getFullYear()
	var errorAr      = new Array();
	
	if( R_BIRTHDAY_YEAR +'.'+ R_BIRTHDAY_MONTH +'.'+ R_BIRTHDAY_DAY != yearThis +'.'+ monthThis +'.'+ dayThis){
	
		errorAr.push( 1 ) 

	}
	
	if( errorAr.length == 0 ){
		return true;
	}else{
		return false;
	}
	
}

проверка mail javascript

14.01.2013 javascript 1 comment , , , , ,

if(EMAIL != ''){

			var checkMail = (
									EMAIL &&
									EMAIL.indexOf('@') > 0 &&
									EMAIL.toLowerCase().match(/^(?:[-a-z\d\+\*\/\?!{}`~_%&'=^$#]+(?:\.[-a-z\d\+\*\/\?!{}`~_%&'=^$#]+)*)@(?:[-a-z\d_]+\.){1,60}[a-z]{2,6}$/)
								) ? true : false;
			
			if(checkMail){
				hideError('EMAIL');
			}else{		
				showError('EMAIL');
				errorArr.push(1);
			}
		}else{
		
			showError('EMAIL');
			errorArr.push(1);
		
		}

Из result_modifier.php в component_epilog.php

10.01.2013 Bitrix No comments , ,

Для получения всех данных из шаблона в component_epilog.php

result_modifier.php

<?if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();

$cp = $this->__component; // объект компонента

if (is_object($cp))
{
   // добавим в arResult компонента два поля - MY_TITLE и IS_OBJECT
   $cp->arResult['arResult'] = $arResult;
   
   $cp->SetResultCacheKeys(array('arResult'));
   // сохраним их в копии arResult, с которой работает шаблон, если модуль main меньше 10.0
   if (!isset($arResult['arResult']))
   {
      $arResult['arResult'] = $cp->arResult['arResult'];
   }
}?>

component_epilog.php

$arResult = $this->arResult['arResult'];

Полезности по Bitrix

25.12.2012 Bitrix No comments

Курс для хостера
https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=32

Курс Администратор Бизнес
https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=42

Контент-менеджер для Net Forge
https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=54

Курс для пользователей Б24
https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=52

Курс Разработчик Bitrix Framework
https://dev.1c-bitrix.ru/learning/course/index.php?COURSE_ID=43

Расчет центра Яндекс.Карты

14.12.2012 Bitrix, javascript ,

<?
 foreach($arResult["YANDEX_COORD"]["PLACEMARKS"] as $arItemKey=>$arItem)
 {
  $min_x = ($arItem["LAT"]<$min_x || !$min_x)? $arItem["LAT"] : $min_x;
  $max_x = ($arItem["LAT"]>$max_x || !$max_x)? $arItem["LAT"] : $max_x;
  $min_y = ($arItem["LON"]<$min_y || !$min_y)? $arItem["LON"] : $min_y;
  $max_y = ($arItem["LON"]>$max_y || !$max_y)? $arItem["LON"] : $max_y;
 }

 $x = round((($max_x - $min_x)/2 + $min_x), 6);
 $y = round((($max_y - $min_y)/2 + $min_y), 6);

 $arResult["YANDEX_COORD"]['yandex_lat'] = $x;
 $arResult["YANDEX_COORD"]['yandex_lon'] = $y;
 ?>

Проверка на совершеннолетие

30.11.2012 javascript No comments , , ,


function checkBirthDay(R_BIRTHDAY_DAY, R_BIRTHDAY_MONTH, R_BIRTHDAY_YEAR){

	if(R_BIRTHDAY_DAY == '' || R_BIRTHDAY_MONTH == '' || R_BIRTHDAY_YEAR == ''){

		return false;
	}
	R_BIRTHDAY_MONTH = R_BIRTHDAY_MONTH - 1; 						
	var thisDate     = new Date(R_BIRTHDAY_YEAR, R_BIRTHDAY_MONTH , R_BIRTHDAY_DAY);
	var dayThis      = thisDate.getDate()
	var monthThis    = thisDate.getMonth()
	var yearThis     = thisDate.getFullYear()
	var errorAr      = new Array();
	
	if( R_BIRTHDAY_YEAR +'.'+ R_BIRTHDAY_MONTH +'.'+ R_BIRTHDAY_DAY != yearThis +'.'+ monthThis +'.'+ dayThis){
	
		errorAr.push( 1 ) 

	}else{
		
		var date = new Date();                   // создается дата "сегодня"
		var year = date.getFullYear();	         // Выбор от "сегодня" года
		
		if(R_BIRTHDAY_YEAR > 1900){				
		
			if((year - R_BIRTHDAY_YEAR) >= 18){}else{			
				errorAr.push( 1 ) 			
			}
			
		}else{			
			errorAr.push( 1 ) 		
		}		
	}
	
	if( errorAr.length == 0 ){
		return true;
	}else{
		return false;
	}
	
}

Превьюшка видео с YouTube.com

26.11.2012 php ,

http://mrafalko.com/post/11/YouTube+API.+%D0%98%D0%BC%D1%8F+%D0%B8+thumbnail

CSV Выгрузка

21.11.2012 Bitrix, php, php скрипты , , ,

<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

	CModule::IncludeModule("iblock");

		$handle = fopen("tb.csv", "r");
		$csv    = array();

		while ( !feof( $handle ) ) {

			$line  = fgets($handle);
			$data  = explode(";", $line);
			$csv[] = $data;

		}

		$rs = new CDBResult;
		$el = new CIBlockElement;

		$rs->InitFromArray($csv);
		$rs->NavStart(1);

		$naumberPageGet = $rs->NavNum;
		$thisPage       = $_GET["PAGEN_".$naumberPageGet];

		if( !isset( $_GET["PAGEN_".$naumberPageGet] ) ){

			$nextPge = "PAGEN_".$naumberPageGet."=2";

		}else{

			if($rs->NavPageCount > $thisPage){
				$thisPage+=1;
				$nextPge = "PAGEN_".$naumberPageGet."=".$thisPage;
			}

		}

		if($rs->IsNavPrint())
		{
			 echo "<p>"; $rs->NavPrint("Элементы"); echo "</p>";
		}

		####
		$clearArray = array();

		$el = new CIBlockElement;

		while($test = $rs->Fetch()){

			$PROP = array();
			$PROP['RATE_GROUP']     = $test[0];
			$PROP['SUM']            = $test[1];
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[2],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[3],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[4],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[5],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[6],"DESCRIPTION" => "");
			$PROP['COEFF_DAMAGE'][] = Array("VALUE" => $test[7],"DESCRIPTION" => "");

			$arLoadProductArray     = Array(
				"MODIFIED_BY"       => $USER->GetID(), // элемент изменен текущим пользователем
				"IBLOCK_SECTION_ID" => false,          // элемент лежит в корне раздела
				"IBLOCK_ID"         => 34,
				"PROPERTY_VALUES"   => $PROP,
				"NAME"              => $test[0],
				"ACTIVE"            => "Y",            // активен
			);

			// if($PRODUCT_ID = $el->Add($arLoadProductArray))
				// itdbg("New ID: ".$PRODUCT_ID);
			// else
				// itdbg("Error: ".$el->LAST_ERROR,true);

			itdbg($arLoadProductArray,false,2);
			echo '<pre>';
			var_dump($arLoadProductArray);
			echo '</pre>';

		}
		###

		$nPage = $rs->NavPageNomer;

		if($thisPage == $nPage){
			itdbg('exi',true, 2);
		}
?>
		<script>
		function second_passed() {
			window.document.location.href = "<?=$APPLICATION->GetCurPageParam($nextPge, array("PAGEN_".$naumberPageGet,"MUS_IMPORT","MUS_TYPE_PROCEDURE")); ?>";
		}
		setTimeout(second_passed, 1000);
		</script>

BITRIX копирование ИБ

09.11.2012 Bitrix, php скрипты No comments ,


require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("iblock");
    if(intval($_REQUEST["IBLOCK_ID_FIELDS"])>0){
        $bError = false;
        $IBLOCK_ID = intval($_REQUEST["IBLOCK_ID_FIELDS"]);
        $ib = new CIBlock;
        $arFields = CIBlock::GetArrayByID($IBLOCK_ID);
        $arFields["GROUP_ID"] = CIBlock::GetGroupPermissions($IBLOCK_ID);
        $arFields["NAME"] = $arFields["NAME"]."_new";
        unset($arFields["ID"]);
        if($_REQUEST["IBLOCK_TYPE_ID"]!="empty")
            $arFields["IBLOCK_TYPE_ID"]=$_REQUEST["IBLOCK_TYPE_ID"];
        $ID = $ib->Add($arFields);
            if(intval($ID)<=0)
                $bError = true;        
        if($_REQUEST["IBLOCK_ID_PROPS"]!="empty")
            $iblock_prop=intval($_REQUEST["IBLOCK_ID_PROPS"]);
        else
            $iblock_prop=$IBLOCK_ID;

        $iblock_prop_new = $ID;
        $ibp = new CIBlockProperty;
        $properties = CIBlockProperty::GetList(Array("sort"=>"asc", "name"=>"asc"), Array("ACTIVE"=>"Y", "IBLOCK_ID"=>$iblock_prop));
        while ($prop_fields = $properties->GetNext()){
            if($prop_fields["PROPERTY_TYPE"] == "L"){
                $property_enums = CIBlockPropertyEnum::GetList(Array("DEF"=>"DESC", "SORT"=>"ASC"), Array("IBLOCK_ID"=>$iblock_prop, "CODE"=>$prop_fields["CODE"]));
                while($enum_fields = $property_enums->GetNext()){
                    $prop_fields["VALUES"][] = Array(
                      "VALUE" => $enum_fields["VALUE"],
                      "DEF" => $enum_fields["DEF"],
                      "SORT" => $enum_fields["SORT"]
                    );
                }
            }
            $prop_fields["IBLOCK_ID"]=$iblock_prop_new;
            unset($prop_fields["ID"]);
            foreach($prop_fields as $k=>$v){
                if(!is_array($v))$prop_fields[$k]=trim($v);
                if($k{0}=='~') unset($prop_fields[$k]);
            }
            $PropID = $ibp->Add($prop_fields);
            if(intval($PropID)<=0)
                $bError = true;
        }
        if(!$bError && $IBLOCK_ID>0)
            LocalRedirect($APPLICATION->GetCurPageParam("success=Y",array("success","IBLOCK_ID_FIELDS")));
        else 
            LocalRedirect($APPLICATION->GetCurPageParam("error=Y",array("success","IBLOCK_ID_FIELDS")));
    }
    $str .='<form action='.$APPLICATION->GetCurPageParam().' method="post"><table>';    
    if($_REQUEST["success"]=="Y") $str .='<tr><td colspan="2"><font color="green">ИБ успешно скопирован</font><br/></td></tr>';
    elseif($_REQUEST["error"]=="Y") $str .='<tr><td colspan="2"><font color="red">Произошла ошибка</font><br/></td></tr>';
    $str .='<tr><td colspan="2"><b>Копируем мета данные ИБ в новый ИБ</b><br/></td></tr>';
    $res = CIBlock::GetList(Array(),Array(),true);
        while($ar_res = $res->Fetch())
            $arRes[]=$ar_res;
    $str .='<tr><td>Копируем ИБ:<br><select name="IBLOCK_ID_FIELDS">';
    foreach($arRes as $vRes)    
        $str .= '<option value='.$vRes['ID'].'>'.$vRes['NAME'].' ['.$vRes["ID"].']</option>';
    $str .='</select></td>';
    $str .='<td>Копируем в новый ИБ свойства другого ИБ: *<br><select name="IBLOCK_ID_PROPS">';
    $str .='<option value="empty">';
    foreach($arRes as $vRes)    
        $str .= '<option value='.$vRes['ID'].'>'.$vRes['NAME'].' ['.$vRes["ID"].']</option>';
    $str .='</select></td></tr>';
    $str .='<tr><td colspan="2">Копируем ИБ в тип:<br><select name="IBLOCK_TYPE_ID">';
    $str .='<option value="empty">';
    $db_iblock_type = CIBlockType::GetList();
    while($ar_iblock_type = $db_iblock_type->Fetch()){
       if($arIBType = CIBlockType::GetByIDLang($ar_iblock_type["ID"], LANG))
          $str .= '<option value='.$ar_iblock_type["ID"].'>'.htmlspecialcharsex($arIBType["NAME"])."</option>";
    }
    $str .='</select></td></tr>';
    $str .='<tr><td colspan="2"><br/>* если значение не указано мета данные ИБ секции "Свойства" берутся из ИБ первого поля</td></tr>';
    $str .='<tr><td colspan="2"><input type="submit" value="копируем"></td></tr>';
    $str .='</table></form>';    
    echo $str;

javascript изменение параметров в GET

26.10.2012 javascript No comments , , ,

-------------------------------------------------------
var queryParameters = {}, queryString = location.search.substring(1),re = /([^&=]+)=([^&]*)/g, m;
   while (m = re.exec(queryString)) {
    queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
   }
   queryParameters['region'] = this.$Button.data('region');
   queryParameters['city'] = this.$Button.data('city');
   
 
   location.search = $.param(queryParameters);
-----------------------------------------------------------------