Documentation

Add

mixed
CUser::Add(
 array fields
)

The method adds a new user. Returns the ID of the added user on success, or false otherwise. In the latter case, the LAST_ERROR property contains the error description. Non-static method.

Note: CUser::Add can be called only as the method of the initialized object, and not as the static method of CUser class.

Parameters

ParameterDescription
fields Array of field values. It is permitted to use as the keys of this array:
  • LOGIN* - login name;
  • NAME - user first name;
  • LAST_NAME - user last name;
  • SECOND_NAME - user middle name;
  • EMAIL* - user e-mail address;
  • PASSWORD* - user password;
  • CONFIRM_PASSWORD* - password confirmation (must be equal to PASSWORD);
  • GROUP_ID - array of group IDs that will include the specific user;
  • ACTIVE - user active state flag [Y|N];
  • LID - site ID by default for notifications;
  • ADMIN_NOTES - administrator notes;
  • XML_ID - user ID for connection with external sources (for example, user ID in an external database);
  • EXTERNAL_AUTH_ID - code of an external authorization source;
  • PERSONAL_PROFESSION - name of position;
  • PERSONAL_WWW - personal web site;
  • PERSONAL_ICQ - ICQ number;
  • PERSONAL_GENDER - gender ["M" - male; "F" - female];
  • PERSONAL_BIRTHDAY - date of birth in the current site format (or the current language for administrative section);
  • PERSONAL_PHOTO - array that describes the photo. the following keys of this array are available:
    • name - file name;
    • size - file size;
    • tmp_name - temporary path on the server;
    • type - type of uploaded file;
    • del - if the value equals "Y", the image will be deleted;
    • MODULE_ID - main module ID - "main";
  • PERSONAL_PHONE - phone;
  • PERSONAL_FAX - fax;
  • PERSONAL_MOBILE - mobile phone;
  • PERSONAL_PAGER - pager;
  • PERSONAL_STREET - street, house;
  • PERSONAL_MAILBOX - mailbox;
  • PERSONAL_CITY - city;
  • PERSONAL_STATE - state or region;
  • PERSONAL_ZIP - zip code;
  • PERSONAL_COUNTRY - country;
  • PERSONAL_NOTES - personal notes;
  • TITLE - how to address the user. Field is relevant when adding or updating the data;
  • WORK_COMPANY - company name;
  • WORK_DEPARTMENT - department;
  • WORK_POSITION - position;
  • WORK_WWW - company web site;
  • WORK_PHONE - work phone;
  • WORK_FAX - work fax;
  • WORK_PAGER - work pager;
  • WORK_STREET - company street;
  • WORK_MAILBOX - company mailbox;
  • WORK_CITY - company city;
  • WORK_STATE - company state or region;
  • WORK_ZIP - company zip code;
  • WORK_COUNTRY - company country;
  • WORK_PROFILE - company profile;
  • WORK_LOGO - array describing company logo. The following keys for this array are available:
    • name - file name;
    • size - file size;
    • tmp_name - temporary path on the server;
    • type - type of uploaded file;
    • del -if the value equals "Y", the image will be deleted;
    • MODULE_ID - main module ID - "main";
  • WORK_NOTES - user work-related notes;
* - required fields.

See Also

Examples of use

<?
// Create an array, describing the image
// located in the file on the server
$arIMAGE = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/images/photo.gif");
$arIMAGE["MODULE_ID"] = "main";

$user = new CUser;
$arFields = Array(
  "NAME"              => "John",
  "LAST_NAME"         => "Harrington",
  "EMAIL"             => "john@bitrix24.com",
  "LOGIN"             => "john",
  "LID"               => "en",
  "ACTIVE"            => "Y",
  "GROUP_ID"          => array(10,11),
  "PASSWORD"          => "123456",
  "CONFIRM_PASSWORD"  => "123456",
  "PERSONAL_PHOTO"    => $arIMAGE
);

$ID = $user->Add($arFields);
if (intval($ID) > 0)
    echo "User has been successfully added.";
else
    echo $user->LAST_ERROR;
?>


© «Bitrix24», 2001-2022
Up