В /bitrix/php_interface/init.php добавить
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
<?php // Add custom field in email send order AddEventHandler("sale", "OnOrderNewSendEmail", Array("EmailHandler", "SendInvoice")); // require field and throw AddEventHandler("main", "OnBeforeUserRegister", Array("UserHandler", "RequireField")); AddEventHandler("main", "OnBeforeUserUpdate", Array("UserHandler", "RequireField")); // PersonType If user IsAuthorized AddEventHandler("sale", "OnSaleComponentOrderOneStepPersonType", Array("UserHandler", "PersonTypeOrderMake")); // add custom field out $_REQUEST AddEventHandler("main", "OnBeforeUserRegister", Array("UserHandler", "HandlerAddSecondName")); // проверка login только латинские символы и цифры AddEventHandler("main", "OnBeforeUserRegister", Array("UserHandler", "LoginCheck")); AddEventHandler("main", "OnBeforeUserUpdate", Array("UserHandler", "LoginCheck")); // Регистрация пользователя через корзину AddEventHandler("main", "OnBeforeUserAdd", Array("GuestHandler", "RegistrationUser")); // Восстановление пароля AddEventHandler("main", "OnBeforeUserUpdate", Array("UserHandler", "ForgotPassword")); /** * Запись логов * @param string $string строка с данными/массив * @param string $path файл куда сохраняем */ function LogWriter($string, $path = "RegistrationUser") { $file = fopen($_SERVER['DOCUMENT_ROOT'].'/logs/'. $path .'.log', 'a+'); fwrite($file, json_encode($string, JSON_UNESCAPED_UNICODE).PHP_EOL."\t\t\t\t=========".PHP_EOL); fclose($file); } $userInformation = Array(); class EmailHandler { function SendInvoice($ID, &$eventName, &$arFields, $val) { global $userInformation; if ($userInformation['REG_NEW_USER'] == "Y"){ $arRegFields = array( "LOGIN" => $userInformation['arFields']['LOGIN'], "PASSWORD" => $userInformation['arFields']['PASSWORD'], "NAME" => $userInformation['arFields']['NAME'], "LAST_NAME" => $userInformation['arFields']['LAST_NAME'], "SECOND_NAME" => $userInformation['arFields']['SECOND_NAME'], "URL_PERSONAL" => $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://' . $_SERVER['HTTP_HOST']."/personal/profile/", "EMAIL" => $userInformation['arFields']['EMAIL'], ); CEvent::Send("NEW_USER_AUTO",'s1',$arRegFields, "N"); } LogWriter($arFields, 'EmailHandler.SendInvoice.arFields'); LogWriter($_REQUEST, 'EmailHandler.SendInvoice.REQUEST'); LogWriter($userInformation, 'EmailHandler.SendInvoice.userInformation'); LogWriter($arRegFields, 'EmailHandler.SendInvoice.arRegFields'); $arFields["CUSTOM_FIELD_FILE"] = $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://' . $_SERVER['HTTP_HOST'] . '/personal/orders/detail.php?ID='.$ID; } } class UserHandler { function ForgotPassword(&$arFields) { if ($_REQUEST['TYPE'] == "CHANGE_PWD" && $_REQUEST['AUTH_FORM'] == "Y" && $_REQUEST['change_password'] == "yes"){ global $USER; $USER = !is_object($USER) ? new CUser : $USER; $USER->Authorize($arFields['ID']); } } function LoginCheck(&$arFields) { if (!preg_match("/^[a-zA-Z0-9_-]+$/", $arFields['LOGIN'])){ global $APPLICATION; $APPLICATION->throwException('Логин может состоять из латинских букв, цифр, знаков "-" и "_"'); return false; } } function RequireField(&$arFields) { $errors = false; global $APPLICATION; if (!$_REQUEST['USER_SECOND_NAME'] && !$arFields['SECOND_NAME']){ $APPLICATION->throwException("Пожалуйста, введите Отчество."); $errors = true; } if (!$arFields['NAME']){ $APPLICATION->throwException("Пожалуйста, введите Имя."); $errors = true; } if (!$arFields['LAST_NAME']){ $APPLICATION->throwException("Пожалуйста, введите Фамилию."); $errors = true; } return ($errors) ? false : true; } function PersonTypeOrderMake(&$arResult, &$arUserResult) { global $USER; if($USER->IsAuthorized()) { $rsUser = $USER->GetByID($USER->GetID()); $arUser = $rsUser->Fetch(); $personType = $arUser['UF_TYPE_FACE']; //очищаем текущее значение типа плательщика foreach($arResult['PERSON_TYPE'] as $key => $type){ if($type['CHECKED'] == 'Y'){ unset($arResult['PERSON_TYPE'][$key]['CHECKED']); } } //устанавливаем новое значение типа плательщика $arResult['PERSON_TYPE'][$personType]['CHECKED'] = 'Y'; $arUserResult['PERSON_TYPE_ID'] = $personType; } } function HandlerAddSecondName(&$arFields) { LogWriter($arFields, "UserHandler.HandlerAddSecondName.arFields"); LogWriter($_REQUEST, "UserHandler.HandlerAddSecondName.REQUEST"); $arFields["SECOND_NAME"] = $_REQUEST['USER_SECOND_NAME']; } } class GuestHandler { function RegistrationUser(&$arFields) { LogWriter($_REQUEST, "GuestHandler.RegistrationUser.REQUEST"); LogWriter($arFields, "GuestHandler.RegistrationUser.arFields"); if ($arFields['NAME'] != 'Анонимный пользователь' && $arFields['ACTIVE'] == 'Y' && $_REQUEST['TYPE'] != 'REGISTRATION'){ global $userInformation; $fio = $_REQUEST['PERSON_TYPE'] == 2 ? $_REQUEST['ORDER_PROP_12'] : $_REQUEST['ORDER_PROP_1']; $arFields['SECOND_NAME'] = explode(" ", $fio)[2]; // отчество $arFields['UF_TYPE_FACE'] = $_REQUEST['PERSON_TYPE']; // Тип плательщика $arFields['UF_INN'] = $_REQUEST['ORDER_PROP_10']; // ИНН $arFields['UF_KPP'] = $_REQUEST['ORDER_PROP_11']; // КПП $arFields['WORK_COMPANY'] = $_REQUEST['ORDER_PROP_8']; // Название компании $userInformation['arFields'] = $arFields; $userInformation['REQUEST'] = $_REQUEST; $userInformation['REG_NEW_USER'] = "Y"; } } } |
full
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
<?php // Add custom field in email send order AddEventHandler("sale", "OnOrderNewSendEmail", Array("EmailHandler", "SendInvoice")); // require field and throw AddEventHandler("main", "OnBeforeUserRegister", Array("UserHandler", "RequireField")); AddEventHandler("main", "OnBeforeUserUpdate", Array("UserHandler", "RequireField")); // PersonType If user IsAuthorized AddEventHandler("sale", "OnSaleComponentOrderOneStepPersonType", Array("UserHandler", "PersonTypeOrderMake")); // add custom field out $_REQUEST AddEventHandler("main", "OnBeforeUserRegister", Array("UserHandler", "HandlerAddSecondName")); // проверка login только латинские символы и цифры AddEventHandler("main", "OnBeforeUserRegister", Array("UserHandler", "LoginCheck")); AddEventHandler("main", "OnBeforeUserUpdate", Array("UserHandler", "LoginCheck")); // Регистрация пользователя через корзину AddEventHandler("main", "OnBeforeUserAdd", Array("GuestHandler", "RegistrationUser")); // Восстановление пароля AddEventHandler("main", "OnBeforeUserUpdate", Array("UserHandler", "ForgotPassword")); /** * Запись логов * @param string $string строка с данными/массив * @param string $path файл куда сохраняем */ function LogWriter($string, $path = "RegistrationUser") { $file = fopen($_SERVER['DOCUMENT_ROOT'].'/logs/'. $path .'.log', 'a+'); fwrite($file, json_encode($string, JSON_UNESCAPED_UNICODE).PHP_EOL."\t\t\t\t=========".PHP_EOL); fclose($file); } $userInformation = Array(); class OrderHandler { function Agreement(&$arFields) { LogWriter($arFields, 'OrderHandler.Agreement.arFields'); LogWriter($_REQUEST, 'OrderHandler.Agreement.request'); } } class EmailHandler { function SendInvoice($ID, &$eventName, &$arFields, $val) { global $userInformation; if ($userInformation['REG_NEW_USER'] == "Y"){ $arRegFields = Array( "LOGIN" => $userInformation['arFields']['LOGIN'], "PASSWORD" => $userInformation['arFields']['PASSWORD'], "NAME" => $userInformation['arFields']['NAME'], "LAST_NAME" => $userInformation['arFields']['LAST_NAME'], "SECOND_NAME" => $userInformation['arFields']['SECOND_NAME'], "URL_PERSONAL" => $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://' . $_SERVER['HTTP_HOST']."/personal/profile/", "EMAIL" => $userInformation['arFields']['EMAIL'], ); CEvent::Send("NEW_USER_AUTO",'s1',$arRegFields, "N"); } LogWriter($arFields, 'EmailHandler.SendInvoice.arFields'); LogWriter($_REQUEST, 'EmailHandler.SendInvoice.REQUEST'); LogWriter($userInformation, 'EmailHandler.SendInvoice.userInformation'); LogWriter($arRegFields, 'EmailHandler.SendInvoice.arRegFields'); $arFields["CUSTOM_FIELD_FILE"] = 'Подробнее о заказе и квитанция на оплату: ' . $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://' . $_SERVER['HTTP_HOST'] . '/personal/orders/detail.php?ID=' . $ID; } } class UserHandler { function ForgotPassword(&$arFields) { if ($_REQUEST['TYPE'] == "CHANGE_PWD" && $_REQUEST['AUTH_FORM'] == "Y" && $_REQUEST['change_password'] == "yes"){ global $USER; $USER = !is_object($USER) ? new CUser : $USER; $USER->Authorize($arFields['ID']); } } function LoginCheck(&$arFields) { if (!preg_match("/^[a-zA-Z0-9_-]+$/", $arFields['LOGIN']) && $_REQUEST['TYPE'] != "CHANGE_PWD"){ global $APPLICATION; $APPLICATION->throwException('Логин может состоять из латинских букв, цифр, знаков "-" и "_"'); return false; } } function RequireField(&$arFields) { if ($_SERVER['SCRIPT_NAME'] != "/bitrix/admin/user_edit.php" && $_REQUEST['TYPE'] != "CHANGE_PWD"): $errors = false; global $APPLICATION; if (!$_REQUEST['USER_SECOND_NAME'] && !$arFields['SECOND_NAME']){ $APPLICATION->throwException("Пожалуйста, введите Отчество."); $errors = true; } if (!$arFields['NAME']){ $APPLICATION->throwException("Пожалуйста, введите Имя."); $errors = true; } if (!$arFields['LAST_NAME']){ $APPLICATION->throwException("Пожалуйста, введите Фамилию."); $errors = true; } return ($errors) ? false : true; endif; } function PersonTypeOrderMake(&$arResult, &$arUserResult) { global $USER; if($USER->IsAuthorized()) { $rsUser = $USER->GetByID($USER->GetID()); $arUser = $rsUser->Fetch(); $personType = $arUser['UF_TYPE_FACE']; //очищаем текущее значение типа плательщика foreach($arResult['PERSON_TYPE'] as $key => $type){ if($type['CHECKED'] == 'Y'){ unset($arResult['PERSON_TYPE'][$key]['CHECKED']); } } //устанавливаем новое значение типа плательщика $arResult['PERSON_TYPE'][$personType]['CHECKED'] = 'Y'; $arUserResult['PERSON_TYPE_ID'] = $personType; } } function HandlerAddSecondName(&$arFields) { LogWriter($arFields, "UserHandler.HandlerAddSecondName.arFields"); LogWriter($_REQUEST, "UserHandler.HandlerAddSecondName.REQUEST"); $arFields["SECOND_NAME"] = $_REQUEST['USER_SECOND_NAME']; } } class GuestHandler { function RegistrationUser(&$arFields) { LogWriter($_REQUEST, "GuestHandler.RegistrationUser.REQUEST"); LogWriter($arFields, "GuestHandler.RegistrationUser.arFields"); if ($arFields['NAME'] != 'Анонимный пользователь' && $arFields['ACTIVE'] == 'Y' && $_REQUEST['TYPE'] != 'REGISTRATION'){ global $userInformation; $fio = $_REQUEST['PERSON_TYPE'] == 2 ? $_REQUEST['ORDER_PROP_12'] : $_REQUEST['ORDER_PROP_1']; $arFields['SECOND_NAME'] = explode(" ", $fio)[2]; // отчество $arFields['UF_TYPE_FACE'] = $_REQUEST['PERSON_TYPE']; // Тип плательщика $arFields['UF_INN'] = $_REQUEST['ORDER_PROP_10']; // ИНН $arFields['UF_KPP'] = $_REQUEST['ORDER_PROP_11']; // КПП $arFields['WORK_COMPANY'] = $_REQUEST['ORDER_PROP_8']; // Название компании $userInformation['arFields'] = $arFields; $userInformation['REQUEST'] = $_REQUEST; $userInformation['REG_NEW_USER'] = "Y"; } } } include_once($_SERVER['DOCUMENT_ROOT']."/bitrix/modules/wsrubi.smtp/classes/general/wsrubismtp.php"); |