34 require_once(
$_SERVER[
"DOCUMENT_ROOT"].
"/bitrix/modules/main/classes/general/csv_data.php");
36 $this->csv =
new CCSVData($fields_type =
"R");
37 $this->csv->LoadFile($csvFilePath);
38 $this->csv->MoveFirst();
39 $this->csv->SetDelimiter($delimiter);
40 $this->csv->SetFirstHeader(
false);
42 if (!$this->arHeader = $this->csv->Fetch())
44 $this->isErrorOccured =
true;
45 $this->errorMessage =
GetMessage(
"CSV_IMPORT_HEADER_NOT_FOUND");
49 foreach($this->arHeader as
$key =>
$val)
50 $this->arHeader[
$key] = mb_strtoupper(
$val);
54 $this->isErrorOccured =
true;
61 if ($this->isErrorOccured || !is_array($this->arHeader) ||
count($this->arHeader) <= 1)
63 $this->errorMessage =
GetMessage(
"CSV_IMPORT_DELIMETER_NOT_FOUND");
67 $success = array_search(
"NAME", $this->arHeader);
70 $this->errorMessage =
GetMessage(
"CSV_IMPORT_NAME_NOT_FOUND");
74 $success = array_search(
"LAST_NAME", $this->arHeader);
77 $this->errorMessage =
GetMessage(
"CSV_IMPORT_LAST_NAME_NOT_FOUND");
86 $iblockID = intval($iblockID);
87 if (CModule::IncludeModule(
"iblock") && $iblockID > 0)
89 $dbIblock = CIBlock::GetByID($iblockID);
90 if ($dbIblock->Fetch())
91 $this->attachIBlockID = $iblockID;
105 static $allchars =
"abcdefghijklnmopqrstuvwxyzABCDEFGHIJKLNMOPQRSTUVWXYZ0123456789";
109 for (
$i = 0;
$i < $pass_len;
$i++)
110 $string .= $allchars[mt_rand(0,
$n)];
133 $this->ignoreDuplicate = (bool)$ignore;
138 if (is_callable($functionName))
150 $this->defaultEmail =
$email;
155 if ($this->defaultEmail !==
false)
158 return COption::GetOptionString(
"main",
"email_from",
"admin@".
$_SERVER[
"SERVER_NAME"]);
168 $groupID = intval($groupID);
170 if (!$rsGroup->Fetch())
173 if (!is_array($this->userGroups))
174 $this->userGroups = Array();
176 $this->userGroups[] = $groupID;
182 $relativePath =
Rel2Abs(
"/", $relativePath);
183 if (is_dir(
$_SERVER[
"DOCUMENT_ROOT"].$relativePath))
184 $this->imageFilePath = rtrim(
$_SERVER[
"DOCUMENT_ROOT"].$relativePath,
"/");
189 if ($this->attachIBlockID < 1)
193 $dbRes = CUserTypeEntity::GetList(Array(), Array(
"ENTITY_ID" =>
"USER",
"FIELD_NAME" => $this->userPropertyName));
196 $arLabelNames = Array();
198 while($arLanguage = $rsLanguage->Fetch())
201 $arLabelNames[$arLanguage[
"LID"]] =
GetMessage(
"DEPARTMENT_USER_PROPERTY_NAME");
205 'ENTITY_ID' =>
'USER',
206 'FIELD_NAME' => $this->userPropertyName,
207 'USER_TYPE_ID' =>
'iblock_section',
212 'SHOW_FILTER' =>
'I',
213 'SHOW_IN_LIST' =>
'Y',
214 'EDIT_IN_LIST' =>
'Y',
215 'IS_SEARCHABLE' =>
'Y',
218 'LIST_HEIGHT' =>
'8',
219 'IBLOCK_ID' => $this->attachIBlockID,
222 "EDIT_FORM_LABEL" => $arLabelNames,
223 "LIST_COLUMN_LABEL" => $arLabelNames,
224 "LIST_FILTER_LABEL" => $arLabelNames,
243 $csvSectionCode =
"IBLOCK_SECTION_NAME_".$i;
244 if (!array_key_exists($csvSectionCode,
$arFields))
247 $sectionName = trim(
$arFields[$csvSectionCode]);
248 if (mb_strlen($sectionName) < 1)
251 $cacheID = md5($csvSectionCode.
"_".$sectionName.
"_".$sectionID);
252 if (array_key_exists($cacheID, $this->arSectionCache))
254 $sectionID = $this->arSectionCache[$cacheID];
258 $dbSection = CIBlockSection::GetList(Array(), Array(
"IBLOCK_ID" => $this->attachIBlockID,
"NAME" => $sectionName,
"SECTION_ID" => $sectionID));
259 if ($arGroup = $dbSection->Fetch())
261 $sectionID = $arGroup[
"ID"];
262 $this->arSectionCache[$cacheID] = $sectionID;
267 $arSectionFields = Array(
269 "IBLOCK_SECTION_ID" => $sectionID,
270 "IBLOCK_ID" => $this->attachIBlockID,
271 "NAME" => $sectionName,
274 $sectionID = (int)$iblockSection->Add($arSectionFields);
276 $this->arSectionCache[$cacheID] = $sectionID;
286 if ($this->isErrorOccured)
289 $this->errorMessage =
"";
293 if (!$arUser = $this->csv->FetchDelimiter())
297 foreach($this->arHeader as $index =>
$key)
298 if((
$f = trim($arUser[$index])) <>
'')
303 $this->errorMessage =
GetMessage(
"CSV_IMPORT_NO_NAME").
" (".implode(
", ",
$arFields).
").<br>";
307 if (!array_key_exists(
"LAST_NAME",
$arFields) || mb_strlen(
$arFields[
"LAST_NAME"]) < 1)
309 $this->errorMessage =
GetMessage(
"CSV_IMPORT_NO_LASTNAME").
" (".implode(
", ",
$arFields).
").<br>";
320 if (!array_key_exists(
"LOGIN",
$arFields))
329 if ($this->externalAuthID !==
null && !array_key_exists(
"EXTERNAL_AUTH_ID",
$arFields))
332 if (!array_key_exists(
"XML_ID",
$arFields))
333 $arFields[
"XML_ID"] = Random::getString(32);
336 $arFields[
"CHECKWORD"] = Random::getString(32);
338 if ($this->imageFilePath !==
null)
340 if (array_key_exists(
"PERSONAL_PHOTO",
$arFields) &&
$arFields[
"PERSONAL_PHOTO"] <>
'')
342 $arFile = CFile::MakeFileArray($this->imageFilePath.
"/".
$arFields[
"PERSONAL_PHOTO"]);
343 $arFile[
"MODULE_ID"] =
"main";
349 $arFile = CFile::MakeFileArray($this->imageFilePath.
"/".
$arFields[
"WORK_LOGO"]);
350 $arFile[
"MODULE_ID"] =
"main";
367 if($user->LAST_ERROR <>
'')
368 $this->errorMessage =
$arFields[
"NAME"].
" ".
$arFields[
"LAST_NAME"].
": ".$user->LAST_ERROR;
371 if ($userID <= 0 && $this->ignoreDuplicate ===
false)
377 $rsUser = CUser::GetByLogin(
$arFields[
"LOGIN"]);
378 if (!$rsUser->Fetch())
393 if ($this->attachIBlockID > 0)
396 if ($iblockSectionID > 0)
398 if (!$this->isUserPropertyCreate)
404 $user->Update($userID, $arUpdate);
static GetByID($ID, $SHOW_USERS_AMOUNT="N")
static GetList($by="sort", $order="asc", $arFilter=[])
SetCallback($functionName)
__construct($csvFilePath, $delimiter)
IgnoreDuplicate($ignore=true)
SetExternalAuthID($externalAuthID)
SetImageFilePath($relativePath)
SetUserPropertyName($userPropertyName)
AttachUsersToIBlock($iblockID)
__GetIBlockSectionID(&$arFields)
GenerateUserPassword($pass_len=10)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
$_SERVER["DOCUMENT_ROOT"]
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Rel2Abs($curdir, $relpath)
GetMessage($name, $aReplace=null)
check_email($email, $strict=false, $domainCheck=false)
CheckDateTime($datetime, $format=false)
if(empty($signedUserToken)) $key
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"