Skip to content

Instantly share code, notes, and snippets.

@andrei99
Last active July 8, 2021 08:04
Show Gist options
  • Save andrei99/ece5bca96f931bfff6da6d9aa5817325 to your computer and use it in GitHub Desktop.
Save andrei99/ece5bca96f931bfff6da6d9aa5817325 to your computer and use it in GitHub Desktop.
Sender Bitrix
$cnt = 1;
$strDlmtr = ';';
$lineDlmtr = "\n";
$i = 1;
for ($cnt = 1; $cnt <= 15; $cnt++):
$arUsers = array();
$strName = 'users_' . $cnt;
$expUsersFile = $strName . '.csv';
$userParams = array(
'NAV_PARAMS' => array(
"iNumPage" => $cnt,
"nPageSize" => 5000
)
);
$arUsers = array('#;ID;Дата регистрации;Фамилия;Имя;EMail');
$arUsersList = array();
$db = CUser::GetList(($by = 'date_register'), ($order = 'asc'), array(), $userParams);
while ($u = $db->Fetch()) {
$dataReg = explode(' ', $u['DATE_REGISTER']);
$tmp = array($i++, $u['ID'], $dataReg[0], $u['LAST_NAME'], $u['NAME'], $u['EMAIL']);
$arUsers[] = implode($strDlmtr, $tmp);
}
unset($db);
$strUsers = implode($lineDlmtr, $arUsers);
$f = file_put_contents($expUsersFile, iconv('utf-8', 'windows-1251//TRANSLIT', $strUsers));
endfor;
//html
<form enctype="multipart/form-data" method="post">
<input type="file" name="place_file[]" multiple>
</fotm>
//php
$obContext = Context::getCurrent();
$obRequest = $obContext->getRequest();
$arFileAll = array();
$arFileID = array();
if(!empty($_FILES['place_file'])){
foreach ($_FILES['place_file']['tmp_name'] as $key => $arFile){
$arFileAll[$key]['name'] = $_FILES['place_file']['name'][$key];
$arFileAll[$key]['size'] = $_FILES['place_file']['size'][$key];
$arFileAll[$key]['tmp_name'] = $_FILES['place_file']['tmp_name'][$key];
$arFileAll[$key]['type'] = $_FILES['place_file']['type'][$key];
}
foreach ($arFileAll as $arFile){
$arFile['old_file'] = '';
$arFile['del'] = 'Y';
$arFile['MODULE_ID'] = 'iblock';
$arFileID[] = \CFile::SaveFile($arFile, "main");
}
}
//to IB
$obElement = new CIBlockElement;
$arProp = array(
"EMAIL" => $strEmail,
"DATE" => $strDate,
"PLACE_FILE" => $arFileAll
);
$arFields = array(
'IBLOCK_ID' => $arParams['IBLOCK_ID'],
'NAME' => $strFieldName,
'DETAIL_TEXT' => $strDetailText,
'PROPERTY_VALUES' => $arProp,
'ACTIVE' => 'N'
);
$obResult = $obElement->Add($arFields);
//to email
$arMailFields = array(
'EVENT_NAME' => $arParams['EVENT_NAME'],
'LID' => $obContext->getSite(),
'C_FIELDS' => array(
'NAME' => $strName,
'PHONE' => $strPhone,
),
'FILE' => $arFileID
);
Event::send($arMailFields);
require $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include.php';
use Bitrix\Main\Application;
use Bitrix\Main\Context;
$obRequest = Application::getInstance()->getContext()->getRequest();
if (\Bitrix\Main\Loader::includeModule('sender') && !empty($obRequest->get('email'))) {
$strEmail = $obRequest->get('email');
// add row to unsubscribe list
$contactId = \Bitrix\Sender\ContactTable::addIfNotExist(array('EMAIL' => $strEmail));
if($contactId)
{
\Bitrix\Sender\ContactListTable::addIfNotExist($contactId, 7);
echo 'ok';
}
}
перезагружаем Apache:
service httpd restart
if($arPropertyFields["TYPE"] === "FILE"){
$file = $this->request->getFile($arPropertyFields['CODE']);
$value = CFile::SaveFile($file, strtolower($arPropertyFields['CODE']));
} else{
foreach ($this->request as $key => $val) {
if (strtolower($key) == strtolower($arPropertyFields['CODE'])) {
$value = $val;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment