Skip to content

Instantly share code, notes, and snippets.

@bxtimur
Last active January 30, 2020 13:28
Show Gist options
  • Save bxtimur/39d0a4610247ee367782b241fa041da2 to your computer and use it in GitHub Desktop.
Save bxtimur/39d0a4610247ee367782b241fa041da2 to your computer and use it in GitHub Desktop.
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
use Bitrix\Main\Mail\Event,
Bitrix\Main\Application,
\Bitrix\Main\Loader;
Loader::includeModule("iblock");
$request = Application::getInstance()->getContext()->getRequest();
$arProperties = array(
"NAME" => $request->getPost("name"),
"PHONE" => $request->getPost("phone"),
"MAIL" => $request->getPost("mail"),
"PAGE" => $request->getPost("page"),
"VIEW" => $request->getPost("view"),
);
$files = $request->getFile("file");
if (!empty($files)) {
foreach ($files['name'] as $fkey => $name) {
$key = "n" . $fkey;
$arProperties['FILES'][$key] = array(
"VALUE" => array (
"name" => $files['name'][$fkey],
"size" => $files['size'][$fkey],
"tmp_name" => $files['tmp_name'][$fkey],
"type" => $files['type'][$fkey]
)
);
}
}
$arFields = array(
"IBLOCK_ID" => FEEDBACK_IBLOCK_ID,
"NAME" => "заявка от " . date("d.m.Y H:i:s"),
"PROPERTY_VALUES" => $arProperties,
"PREVIEW_TEXT" => $request->getPost("text")
);
$objElement = new CIBlockElement;
if ($element = $objElement->Add($arFields)) {
if (!empty($files)) {
unset($arFields['FILES']);
$resElement = CIblockElement::GetList(array(), array('IBLOCK_ID' => FEEDBACK_IBLOCK_ID, 'ID' => $element), false, false, array());
$obElement = $resElement->GetNextElement();
$arElement = $obElement->GetFields();
$arElement['PROPERTIES'] = $obElement->GetProperties();
foreach ($arElement['PROPERTIES']['FILES']['VALUE'] as $file) {
$arFields['FILES'][] = FULL_SITE_URL . CFile::GetPath($file);
}
}
echo 'success';
} else {
echo $objElement->LAST_ERROR;
}
// отправим письмо
foreach ($arProperties as &$arProperty) {
if (is_array($arProperty))
$arProperty = implode(", ", $arProperty);
}
$arProperties['TEXT'] = $arFields['PREVIEW_TEXT'];
Event::send(array(
"EVENT_NAME" => "CALLBACK",
"LID" => "s1",
"C_FIELDS" => $arProperties,
));
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment