Ejemplo n.º 1
0
 static function onBeforeElementAddHandler($arFields)
 {
     $IBLOCK_ID = Config\Option::get("citfact.replaceurl", "IBLOCK_ID", "");
     $SECTION_ID = Config\Option::get("citfact.replaceurl", "SECTION_BREND_ID", "BRENDI");
     $CODE_PROP = Config\Option::get("citfact.replaceurl", "PROPERTY_CODE_BRENDI", "BRENDI");
     if ($IBLOCK_ID == $arFields["IBLOCK_ID"]) {
         $propertyBrand = \CIBlockProperty::GetByID($CODE_PROP, $arFields["IBLOCK_ID"]);
         if ($arResultProperty = $propertyBrand->GetNext()) {
             $propertyBrandValue = \CIBlockPropertyEnum::GetByID($arFields["PROPERTY_VALUES"][$arResultProperty["ID"]][0]["VALUE"]);
         }
         $rqParentSection = \CIBlockSection::GetByID($SECTION_ID);
         if ($arParentSection = $rqParentSection->GetNext()) {
             $arFilter = array('IBLOCK_ID' => $arParentSection['IBLOCK_ID'], '>LEFT_MARGIN' => $arParentSection['LEFT_MARGIN'], '<RIGHT_MARGIN' => $arParentSection['RIGHT_MARGIN'], '>DEPTH_LEVEL' => $arParentSection['DEPTH_LEVEL']);
             // выберет потомков без учета активности
             $rqSectChild = \CIBlockSection::GetList(array('left_margin' => 'asc'), $arFilter);
             while ($arSectChild = $rqSectChild->GetNext()) {
                 $arSections[$arSectChild["NAME"]] = $arSectChild["ID"];
             }
         }
         if (array_key_exists($propertyBrandValue["VALUE"], $arSections)) {
             $arFields["IBLOCK_SECTION"][] = $arSections[$propertyBrandValue["VALUE"]];
         } else {
             $arParams = array("replace_space" => "-", "replace_other" => "-");
             $trans = \Cutil::translit($propertyBrandValue["VALUE"], "ru", $arParams);
             $bs = new \CIBlockSection();
             $arFieldsNewSection = array("ACTIVE" => "Y", "IBLOCK_SECTION_ID" => $SECTION_ID, "IBLOCK_ID" => $IBLOCK_ID, "NAME" => $propertyBrandValue["VALUE"], "CODE" => $trans);
             $resultAdd = $bs->Add($arFieldsNewSection);
             $arFields["IBLOCK_SECTION"][] = $resultAdd;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public static function GeneratePassword($login, $name)
 {
     $name = strtolower(trim($name));
     $arParams = array("replace_space" => "-", "replace_other" => "-");
     $name = Cutil::translit($name, "ru", $arParams);
     $pass = substr($name, 0, 3) . substr($login, -3);
     $pass = str_pad($pass, 6, "0");
     return $pass;
 }
Ejemplo n.º 3
0
    /**
     * функция перед добавлениемредактированием элемента в инфоблок
     * @param $arFields поля элемента ифоблока
     * для страницы Объявления
     * создает нового пользователя
     * отправляет логини и пароль по почтовому шаблону
     * добавляет цену и количество в Торговый каталог
     */
    function OnBeforeIBlockElementAddHandler(&$arFields)
    {


        if (
        ((
                ($arFields["IBLOCK_ID"] == 2)
                ||
                ($arFields["IBLOCK_ID"] == 15)
                ||
                ($arFields["IBLOCK_ID"] == 14)
                ||
                ($arFields["IBLOCK_ID"] == 16)
                ||
                ($arFields["IBLOCK_ID"] == 19)
            )
            &&
            (strstr($_SERVER['REQUEST_URI'],'/personal/moy-magazin/')))
            &&
            ((!$_REQUEST['active'])&&(!$_REQUEST['deactive']))
        ||
        (

                ($arFields["IBLOCK_ID"] == 16)

            &&
            (strstr($_SERVER['REQUEST_URI'],'/obyavleniya/add-ads/')))
            &&
            ((!$_REQUEST['active'])&&(!$_REQUEST['deactive']))

        )
        {

            $rsUser = CUser::GetByID(CUser::GetID());
            $arUser = $rsUser->Fetch();
            $ID=$arUser['ID'];
            $arSelect = Array("ID", "IBLOCK_ID", "NAME","PROPERTY_*");
            $arFilter = Array("IBLOCK_ID"=>9, "ACTIVE"=>"Y","PROPERTY_PARTNER"=>intval($ID));
            $res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>1), $arSelect);
            while($ob = $res->GetNextElement()){
                $arFields_partner = $ob->GetFields();
                $id_block_partner=$arFields_partner['ID'];
            }
            if($id_block_partner){
                switch($arFields["IBLOCK_ID"]){
                    case 2:
                            $arFields["PROPERTY_VALUES"][59]["VALUE"]=$id_block_partner;
                        break;
                    case 14:
                            $arFields["PROPERTY_VALUES"][66]["VALUE"]=$id_block_partner;
                        break;
                    case 15:
                            $arFields["PROPERTY_VALUES"][71]["VALUE"]=$id_block_partner;
                    break;
                    case 16:
                            $arFields["PROPERTY_VALUES"][104]["VALUE"]=$id_block_partner;
                    break;
                    case 19:
                        $arFields["PROPERTY_VALUES"][105]["VALUE"]=$id_block_partner;
                    break;
                }
            }
        }


        if (
            (

            (($arFields["IBLOCK_ID"] == 16))
            )
            &&
            CModule::IncludeModule("catalog")
            &&
            CModule::IncludeModule("sale")
            &&
            ((strstr($_SERVER['REQUEST_URI'],'/obyavleniya/add-ads/')))
            &&
            ((!$_REQUEST['active'])&&(!$_REQUEST['deactive']))
        )
        {
                if(($arFields['PROPERTY_VALUES'][81]==7)||($arFields['PROPERTY_VALUES'][81]=="Y")){
                   //$arFields['PROPERTY_VALUES'][81]=40;
                    //$_SESSION['field_after2']="первый";
                }elseif($arFields['PROPERTY_VALUES'][81]==9){
                    //$_SESSION['field_after1']="второй";
                    //$arFields['PROPERTY_VALUES'][81]=46;
                }

                $arSelect16 = Array("ID", "IBLOCK_ID", "NAME","PROPERTY_*");
                $arFilter16 = Array("IBLOCK_ID"=>18,"ACTIVE"=>"Y","CODE "=>"standart-ads");
                $res16 = CIBlockElement::GetList(Array(), $arFilter16, false, Array("nPageSize"=>1), $arSelect16);
                while($ob16 = $res16->GetNextElement()){

                    $arProps16 = $ob16->GetProperties();
                    $interval_day_ads=$arProps16['INTERVAL_ADS']['VALUE'];
                }
                if($interval_day_ads){
                    $arFields['ACTIVE_TO']=date("d.m.Y H:i:s",mktime(0,0,0,date("m"),date("d")+$interval_day_ads,date("Y")));

                }



                $_SESSION['field_after3']=$arFields;

                    if(!CUser::IsAuthorized()){
                        $chars="qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
                        $max=10;
                        $size=StrLen($chars)-1;
                        $password=null;
                        while($max--)
                            $password.=$chars[rand(0,$size)];
                        $user = new CUser;
                        $arFieldsUser = Array(
                            "NAME"              => $arFields["PROPERTY_VALUES"][89],
                            "EMAIL"             => $arFields["PROPERTY_VALUES"][88],
                            "LOGIN"             => $arFields["PROPERTY_VALUES"][88],
                            "PERSONAL_MOBILE"   => $arFields["PROPERTY_VALUES"][91],
                            "LID"               => "ru",
                            "ACTIVE"            => "Y",
                            "GROUP_ID"          => array(3,4,5),
                            "PASSWORD"          => $password,
                            "CONFIRM_PASSWORD"  => $password
                        );

                        $ID = $user->Add($arFieldsUser);

                    }
                    if(($ID)||(CUser::IsAuthorized())){
                        if(CUser::IsAuthorized()){
                            $rsUser = CUser::GetByID(CUser::GetID());
                            $arUser = $rsUser->Fetch();
                            $ID=$arUser['ID'];
                        }
                        $arFields["CREATED_BY"]=$ID;
                        $arFields["PROPERTY_VALUES"][83]=$ID;
                        $_SESSION['NEW_USER_ID']=$ID;
                    }
                    if($ID){
                        if (strlen($arFields["NAME"]) > 0 && strlen($arFields["CODE"]) <= 0) {
                            $arParams = array(
                                "max_len" => "100", // обрезаем символьный код до 100 символов
                                "change_case" => "L", // приводим к нижнему регистру
                                "replace_space" => "-", // меняем пробелы на тире
                                "replace_other" => "-", // меняем плохие символы на тире
                                "delete_repeat_replace" => "true", // удаляем повторяющиеся тире
                                "use_google" => "false", // отключаем использование google
                            );
                            $arFields["CODE"] = Cutil::translit($arFields["NAME"], "ru", $arParams);
                        }
                        unset($_SESSION['VIP_ID']);
                        if(($arFields["PROPERTY_VALUES"][81][0]=='40')){
                            $_SESSION['VIP_ID']=40;
                        }
                        if(($arFields["PROPERTY_VALUES"][81][0]=='46')){
                            $_SESSION['VIP_ID']=46;
                        }

                    if((!$_REQUEST['CODE'])&&(!CUser::IsAuthorized())){


                        $arEventFields = Array(
                            "NAME"              => $arFields["PROPERTY_VALUES"][89],
                            "EMAIL"             => $arFields["PROPERTY_VALUES"][88],
                            "LOGIN"             => $arFields["PROPERTY_VALUES"][88],
                            "PERSONAL_MOBILE"         => $arFields["PROPERTY_VALUES"][91],
                            "PASSWORD"          => $password,
                        );
                        $event = new CEvent;
                        $event->SendImmediate("MAIN_USER_INFOTEHNOLOG", SITE_ID, $arEventFields);






        }else{


        }

    }
    }
        if (($arFields["IBLOCK_ID"] == 11) &&($arFields["ACTIVE"] == "Y")){
            $_SESSION['active_block'] = $arFields;



            $params = Array(
                "max_len" => "100", // обрезает символьный код до 100 символов
                "change_case" => "L", // буквы преобразуются к нижнему регистру
                "replace_space" => "_", // меняем пробелы на нижнее подчеркивание
                "replace_other" => "_", // меняем левые символы на нижнее подчеркивание
                "delete_repeat_replace" => "true", // удаляем повторяющиеся нижние подчеркивания
                "use_google" => "false", // отключаем использование google
            );



            $el = new CIBlockElement;
            $PROP = array();
            $PROP[108] = $arProps['F_EMAIL']['VALUE'];
            $PROP[60] = $arProps['F_TELEPHONE']['VALUE'];
            $PROP[100] = $arUserLogin['ID'];
            $arElem= Array(
                "CREATED_BY"=>$arUserLogin['ID'],
                "IBLOCK_ID" => 9,
                "NAME" => $arProps['F_NAMECOMPANY']['VALUE'],
                "CODE" => CUtil::translit($arProps['F_NAMECOMPANY']['VALUE'], "ru" , $params),
                "ACTIVE" => "Y",
                "PROPERTY_VALUES"=> $PROP,
            );

            if($PRODUCT_ID = $el->Add($arElem)) {
                if($new_partner){
                    $lg_psswrd="Ваши регистрационные данные: <br> Логин:".$arProps['F_EMAIL']['VALUE']."<br> Пароль:".$password."<br>";
                }else{
                    $lg_psswrd="Ваш логин и пароль были высланы ранее при регистрации данного аккаунта";
                }
            }

        }
    }
Ejemplo n.º 4
0
 private function setDefaultArParamsIblockType()
 {
     $this->arParamsIblockType = array('SECTIONS' => 'N', 'IN_RSS' => 'N', 'SORT' => '500', 'EDIT_FILE_BEFORE' => '', 'EDIT_FILE_AFTER' => '', 'LANG' => array('ru' => array('NAME' => $this->iblockTypeName, 'ELEMENT_NAME' => 'Элементы', 'SECTION_NAME' => 'Разделы'), 'en' => array('NAME' => Cutil::translit($this->iblockTypeName, "ru"), 'ELEMENT_NAME' => 'Elemments', 'SECTION_NAME' => 'Sections')));
 }
Ejemplo n.º 5
0
    public function import($list_value)
    {
        $added = 0;
        $fail = 0;
        $update = 0;
        $tempReport = 1;
        //ID инфоблка путём обрезки из выбронного поля списка
        $IBlockId = str_replace('[', '', explode("]", $list_value)[0]);
        $IBlock = $this->getBlockByID($IBlockId);
        if (isset($_FILES['file']) && $_FILES['file']['size'] > 0) {
            $fileSrc = $_FILES['file']['tmp_name'];
            $xlsx = new \XLSXReader($fileSrc);
            //Используем методы класса XLSXReader
            $sheetNames = $xlsx->getSheetNames();
            foreach ($sheetNames as $sheetName) {
                $sheet = $xlsx->getSheet($sheetName);
                $arSheetList[$sheetName] = $sheet->getData();
                //Массив с ключами элементов
                $arRowNames = $arSheetList[$sheetName][0];
                foreach ($arSheetList[$sheetName] as $row) {
                    for ($i = 0; $i < count($row); $i++) {
                        $arTemp[$arRowNames[$i]] = $row[$i];
                    }
                    $arListRows[] = $arTemp;
                }
                unset($arListRows[0]);
                //Удаляем массив с ключами
                $arList[$sheetName] = $arListRows;
                //Форматированный массив файла .xlsx
                $arListRows = array();
                //обнуляем массив для для случая с несколькими листами
            }
            $arResult['LIST'] = $arList;
            $el = new \CIBlockElement();
            ?>

            <div class="report_detail">
                <button class="close_show_list" id="closeReportDetail" onclick="closeReportDetail();">X</button>

                <?php 
            foreach ($arResult['LIST'] as $arItem) {
                ?>
                    <?php 
                foreach ($arItem as $item) {
                    if (!$item['CODE']) {
                        $arParams = array("replace_space" => "-", "replace_other" => "-");
                        $item['CODE'] = Cutil::translit($item['NAME'], "ru", $arParams);
                    }
                    global $USER;
                    $arLoadProductArray = array("MODIFIED_BY" => $USER->GetID(), "IBLOCK_SECTION_ID" => false, "IBLOCK_ID" => $IBlock['ID'], "NAME" => $item['NAME'], "CODE" => $item['CODE'], "ACTIVE" => $item['ACTIVE'], "PREVIEW_TEXT" => $item['PREVIEW_TEXT'], "DETAIL_TEXT" => $item['DETAIL_TEXT']);
                    $IBlockElement = $this->getBlockElementByCode($item['CODE']);
                    if ($PRODUCT_ID = $el->Add($arLoadProductArray)) {
                        echo $tempReport . ": Added: " . $item['CODE'] . "<br/>";
                        $added++;
                        $tempReport++;
                    } elseif (isset($IBlockElement)) {
                        if ($arLoadProductArray != array_intersect_key($IBlockElement, $arLoadProductArray)) {
                            $el->Update($IBlockElement['ID'], $arLoadProductArray);
                            echo $tempReport . ": Update: " . $IBlockElement['CODE'] . "<br/>";
                            $update++;
                            $tempReport++;
                        }
                    } else {
                        echo $tempReport . ": Error: " . $el->LAST_ERROR;
                        $fail++;
                        $tempReport++;
                    }
                }
            }
            if ($tempReport == 1) {
                echo "Пусто";
            }
            ?>
            </div>
            <div class="report">Added: <?php 
            echo $added;
            ?>
; Updated: <?php 
            echo $update;
            ?>
; Fail: <?php 
            echo $fail;
            ?>
;</div>
            <button class="show_logs">Show Logs</button><?php 
        } else {
            echo "<span class='error_mes'><b>Файл не выбран!</b></span> ";
        }
    }
Ejemplo n.º 6
0
 static function UpdateElementsBadCode()
 {
     $el = new CIBlockElement();
     $arSelect = array("ID", "CODE", "NAME");
     $arFilter = array("IBLOCK_ID" => self::$IBLOCK_ID);
     $obj = $el->GetList(array("id" => "ASC"), $arFilter, false, false, $arSelect);
     while ($arItem = $obj->GetNext()) {
         if (empty($arItem["CODE"]) || preg_match('/^[0-9]+$/', $arItem["CODE"]) || $arItem["CODE"] == "0.00") {
             $new_code = Cutil::translit(trim($arItem["NAME"]), "ru");
             $arFields = array("CODE" => $new_code);
             //                echo "<pre>";
             //                var_dump($arItem["ID"]);
             //                var_dump($arFields);
             //                echo "</pre>";
             $el->Update($arItem["ID"], $arFields);
         }
     }
     return true;
 }
 public static function translit($str)
 {
     $arParams = array("replace_space" => "-", "replace_other" => "-");
     $trans = Cutil::translit($str, "ru", $arParams);
     return $trans;
 }