Adding sent email option in UserManager::add_user and UserManager::update_user see BT#4335

skala
Julio Montoya 13 years ago
parent 1c926535bd
commit b3364704cb
  1. 7
      main/admin/ldap_synchro.php
  2. 63
      main/admin/user_add.php
  3. 41
      main/admin/user_edit.php
  4. 16
      main/admin/user_import.php
  5. 12
      main/auth/conditional_login/complete_phone_number.php
  6. 17
      main/auth/inscription.php
  7. 11
      main/inc/lib/main_api.lib.php
  8. 76
      main/inc/lib/usermanager.lib.php

@ -106,13 +106,10 @@ foreach($Sessions as $session){
$expiration_date='0000-00-00 00:00:00';
$active=1;
// Ajout de l'utilisateur
if (UserManager::is_username_available($username))
{
if (UserManager::is_username_available($username)) {
$user_id = UserManager::create_user($firstname,$lastname,$status,$email,$username,$password,$official_code,api_get_setting('platformLanguage'),$phone,$picture_uri,$auth_source,$expiration_date,$active);
$UserAdd[]=$user_id;
}
else
{
} else {
$user = UserManager::get_user_info($username);
$user_id=$user['user_id'];
UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active);

@ -22,8 +22,6 @@ api_protect_admin_script();
// Database table definitions
$table_admin = Database::get_main_table(TABLE_MAIN_ADMIN);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$database = Database::get_main_database();
$htmlHeadXtra[] = '
<script type="text/javascript">
@ -229,7 +227,6 @@ $defaults = array_merge($defaults, $extra_data);
$form->setDefaults($defaults);
// Submit button
$select_level = array();
$html_results_enabled[] = FormValidator :: createElement ('style_submit_button', 'submit_plus', get_lang('Add').'+', 'class="add"');
$html_results_enabled[] = FormValidator :: createElement ('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
$form->addGroup($html_results_enabled);
@ -238,23 +235,20 @@ $form->addGroup($html_results_enabled);
if( $form->validate()) {
$check = Security::check_token('post');
if ($check) {
$user = $form->exportValues();
$picture_element = & $form->getElement('picture');
$picture = $picture_element->getValue();
$picture_uri = '';
$lastname = $user['lastname'];
$firstname = $user['firstname'];
$official_code = $user['official_code'];
$email = $user['email'];
$phone = $user['phone'];
$username = $user['username'];
$status = intval($user['status']);
$language = $user['language'];
$picture = $_FILES['picture'];
$user = $form->exportValues();
$lastname = $user['lastname'];
$firstname = $user['firstname'];
$official_code = $user['official_code'];
$email = $user['email'];
$phone = $user['phone'];
$username = $user['username'];
$status = intval($user['status']);
$language = $user['language'];
$picture = $_FILES['picture'];
$platform_admin = intval($user['admin']['platform_admin']);
$send_mail = intval($user['mail']['send_mail']);
$hr_dept_id = intval($user['hr_dept_id']);
$send_mail = intval($user['mail']['send_mail']);
$hr_dept_id = intval($user['hr_dept_id']);
if (count($extAuthSource) > 0 && $user['password']['password_auto'] == '2') {
$auth_source = $user['password']['auth_source'];
$password = 'PLACEHOLDER';
@ -262,18 +256,21 @@ if( $form->validate()) {
$auth_source = PLATFORM_AUTH_SOURCE;
$password = $user['password']['password_auto'] == '1' ? api_generate_password() : $user['password']['password'];
}
if ($user['radio_expiration_date'] == '1') {
$expiration_date = $user['expiration_date'];
} else {
$expiration_date = '0000-00-00 00:00:00';
}
$active = intval($user['active']);
if (api_get_setting('login_is_email') == 'true') {
$username = $email;
}
$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, $language, $phone, $picture_uri, $auth_source, $expiration_date, $active, $hr_dept_id);
$user_id = UserManager::create_user($firstname, $lastname, $status, $email, $username, $password, $official_code, $language, $phone, null, $auth_source, $expiration_date, $active, $hr_dept_id, null, null, $send_mail);
Security::clear_token();
$tok = Security::get_token();
if ($user_id === false) {
@ -285,42 +282,20 @@ if( $form->validate()) {
$message .= ucfirst($bit);
}
} else {
if (!empty($picture['name'])) {
$picture_uri = UserManager::update_user_picture($user_id, $_FILES['picture']['name'], $_FILES['picture']['tmp_name']);
UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language);
}
$extras = array();
foreach($user as $key => $value) {
foreach ($user as $key => $value) {
if (substr($key, 0, 6) == 'extra_') { //an extra field
$myres = UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
}
}
if ($platform_admin) {
$sql = "INSERT INTO $table_admin SET user_id = '".$user_id."'";
Database::query($sql);
}
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if ($_configuration['multiple_access_urls']) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
}
else {
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username ."\n". get_lang('Pass')." : ".stripslashes($password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
@api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
$message = get_lang('UserAdded');
}
if (isset($user['submit_plus'])) {

@ -301,6 +301,9 @@ if ( $form->validate()) {
$lastname = $user['lastname'];
$firstname = $user['firstname'];
$password = $user['password'];
$auth_source = $user['auth_source'];
$official_code = $user['official_code'];
$email = $user['email'];
$phone = $user['phone'];
@ -317,24 +320,12 @@ if ( $form->validate()) {
$expiration_date='0000-00-00 00:00:00';
}
$active = $user_data['platform_admin'] ? 1 : intval($user['active']);
if ($reset_password == 0) {
$password = null;
$auth_source = $user_data['auth_source'];
} elseif($reset_password == 1) {
$password = api_generate_password();
$auth_source = PLATFORM_AUTH_SOURCE;
} elseif($reset_password == 2) {
$password = $user['password'];
$auth_source = PLATFORM_AUTH_SOURCE;
} elseif($reset_password == 3) {
$password = $user['password'];
$auth_source = $user['auth_source'];
}
if (api_get_setting('login_is_email') == 'true') {
$username = $email;
}
UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language);
UserManager::update_user($user_id, $firstname, $lastname, $username, $password, $auth_source, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, null, $hr_dept_id, null, $language, null, $send_mail, $reset_password);
if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
$up = UserManager::update_openid($user_id,$user['openid']);
}
@ -352,25 +343,7 @@ if ( $form->validate()) {
if(substr($key, 0, 6) == 'extra_') { //an extra field
UserManager::update_extra_field_value($user_id, substr($key, 6), $value);
}
}
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if ($_configuration['multiple_access_urls']) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username . (($reset_password > 0) ? "\n". get_lang('Pass')." : ".stripslashes($password) : "") . "\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
} else {
$emailbody=get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username . (($reset_password > 0) ? "\n". get_lang('Pass')." : ".stripslashes($password) : "") . "\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
@api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
}
$tok = Security::get_token();
header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
exit();

@ -120,16 +120,13 @@ function save_data($users) {
if (!isset($inserted_in_course)) {
$inserted_in_course = array();
}
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
$send_mail = $_POST['sendMail'] ? 1 : 0;
if (is_array($users)) {
foreach ($users as $index => $user) {
$user = complete_missing_data($user);
$user['Status'] = api_status_key($user['Status']);
$user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource']);
$user_id = UserManager :: create_user($user['FirstName'], $user['LastName'], $user['Status'], $user['Email'], $user['UserName'], $user['Password'], $user['OfficialCode'], api_get_setting('PlatformLanguage'), $user['PhoneNumber'], '', $user['AuthSource'], null, 1, 0, null, null, $send_mail);
if (!is_array($user['Courses']) && !empty($user['Courses'])) {
$user['Courses'] = array($user['Courses']);
}
@ -170,15 +167,6 @@ function save_data($users) {
UserManager::update_extra_field_value($user_id, $key,$value);
}
}
if ($send_mail) {
$recipient_name = api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$emailbody = get_lang('Dear').' '.api_get_person_name($user['FirstName'], $user['LastName']).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ".$user['UserName']."\n".get_lang('Pass')." : ".$user['Password']."\n\n".get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path(WEB_PATH)." \n\n".get_lang('Problem')."\n\n".get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n".get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator')."";
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
@api_mail($recipient_name, $user['Email'], $emailsubject, $emailbody, $sender_name, $email_admin);
}
}
}
}

@ -21,12 +21,12 @@ if (! isset($_SESSION['conditional_login']['uid']))
</html>
<?php
if (isset($_POST['submit'])){
$u = UserManager::get_user_info_by_id($_SESSION['conditional_login']['uid']);
$u['phone'] = $_POST['phone_number'];
$password = null; // we don't want to change the password
$updated = UserManager::update_user($u['user_id'], $u['firstname'], $u['lastname'], $u['username'], $password, $u['auth_source'], $u['email'], $u['status'], $u['official_code'], $u['phone'], $u['picture_uri'], $u['expiration_date'], $u['active'], $u['creator_id'], $u['hr_dept_id'], $u['extra'], $u['language'],'');
if ($updated) {
$u = UserManager::get_user_info_by_id($_SESSION['conditional_login']['uid']);
$u['phone'] = $_POST['phone_number'];
$password = null; // we don't want to change the password
$updated = UserManager::update_user($u['user_id'], $u['firstname'], $u['lastname'], $u['username'], $password, $u['auth_source'], $u['email'], $u['status'], $u['official_code'], $u['phone'], $u['picture_uri'], $u['expiration_date'], $u['active'], $u['creator_id'], $u['hr_dept_id'], $u['extra'], $u['language'],'');
if ($updated) {
ConditionalLogin::login();
}
}
}
?>

@ -8,7 +8,6 @@
use \ChamiloSession as Session;
$language_file = array('registration', 'admin');
if (!empty($_POST['language'])) { //quick hack to adapt the registration form result to the selected registration language
$_GET['language'] = $_POST['language'];
@ -304,7 +303,7 @@ if ($form->validate()) {
}
// creating a new user
$user_id = UserManager::create_user($values['firstname'], $values['lastname'], $values['status'], $values['email'], $values['username'], $values['pass1'], $values['official_code'], $values['language'], $values['phone'], $picture_uri);
$user_id = UserManager::create_user($values['firstname'], $values['lastname'], $values['status'], $values['email'], $values['username'], $values['pass1'], $values['official_code'], $values['language'], $values['phone'], $picture_uri, PLATFORM_AUTH_SOURCE, null, 1, 0, null, null, true);
// Terms & Conditions
if (api_get_setting('allow_terms_conditions') == 'true') {
@ -391,9 +390,7 @@ if ($form->validate()) {
$admin_list = Database::fetch_array($result_list);
$emailto = $admin_list['email'];
// 2. send mail to the platform admin
$emailfromaddr = api_get_setting('emailAdministrator');
$emailfromname = api_get_setting('siteName');
// 2. send mail to the platform admin
$emailsubject = get_lang('ApprovalForNewAccount',null,$values['language']).': '.$values['username'];
$emailbody = get_lang('ApprovalForNewAccount',null,$values['language'])."\n";
$emailbody .= get_lang('UserName',null,$values['language']).': '.$values['username']."\n";
@ -417,7 +414,7 @@ if ($form->validate()) {
unset($user_id);
if (!CustomPages::enabled()) {
Display :: display_footer();
Display :: display_footer();
}
exit;
}
@ -440,7 +437,9 @@ if ($form->validate()) {
Session::write('user_last_login_datetime',$user_last_login_datetime);
/* EMAIL NOTIFICATION */
//already added in UserManager::add_user();
/*
if (strpos($values['email'], '@') !== false) {
// Let us predefine some variables. Be sure to change the from address!
$recipient_name = api_get_person_name($values['firstname'], $values['lastname']);
@ -466,9 +465,9 @@ if ($form->validate()) {
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
@api_mail($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
}*/
}
$recipient_name = api_get_person_name($values['firstname'], $values['lastname']);
$display_text = '<p>'.get_lang('Dear',null,$_user['language']).' '.stripslashes(Security::remove_XSS($recipient_name)).',<br /><br />'.get_lang('PersonalSettings',null,$_user['language']).".</p>\n";
if (!empty ($values['email'])) {

@ -938,7 +938,7 @@ function api_get_user_courses($userid, $fetch_session = true) {
* @param array Non-standard user array
* @return array Standard user array
*/
function _api_format_user($user) {
function _api_format_user($user, $add_password = false) {
$result = array();
if (isset($user['firstname']) && isset($user['lastname'])) {
$firstname = $user['firstname'];
@ -1022,6 +1022,11 @@ function _api_format_user($user) {
$result['user_is_online_in_chat'] = intval($user['user_is_online_in_chat']);
}
if ($add_password) {
$result['password'] = $user['password'];
}
return $result;
}
@ -1032,7 +1037,7 @@ function _api_format_user($user) {
* @author Patrick Cool <patrick.cool@UGent.be>
* @version 21 September 2004
*/
function api_get_user_info($user_id = '', $check_if_user_is_online = false) {
function api_get_user_info($user_id = '', $check_if_user_is_online = false, $show_password = false) {
if ($user_id == '') {
return _api_format_user($GLOBALS['_user']);
}
@ -1054,7 +1059,7 @@ function api_get_user_info($user_id = '', $check_if_user_is_online = false) {
}
$result_array['user_is_online_in_chat'] = $user_online_in_chat;
}
$user = _api_format_user($result_array);
$user = _api_format_user($result_array, $show_password);
return $user;
}
return false;

@ -60,10 +60,11 @@ class UserManager {
* if it exists, $_user['user_id'] is the creator id. If a problem arises,
* it stores the error message in global $api_failureList
*/
public static function create_user($firstName, $lastName, $status, $email, $loginName, $password, $official_code = '', $language = '', $phone = '', $picture_uri = '', $auth_source = PLATFORM_AUTH_SOURCE, $expiration_date = '0000-00-00 00:00:00', $active = 1, $hr_dept_id = 0, $extra = null, $encrypt_method = '') {
public static function create_user($firstName, $lastName, $status, $email, $loginName, $password, $official_code = '', $language = '', $phone = '', $picture_uri = '', $auth_source = PLATFORM_AUTH_SOURCE, $expiration_date = '0000-00-00 00:00:00', $active = 1, $hr_dept_id = 0, $extra = null, $encrypt_method = '', $send_mail = false) {
global $_user, $_configuration;
$original_password = $password;
$access_url_id = 1;
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
}
@ -139,20 +140,37 @@ class UserManager {
$result = Database::query($sql);
if ($result) {
//echo "id returned";
$return = Database::insert_id();
require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
$return = Database::insert_id();
if (api_get_multiple_access_url()) {
UrlManager::add_user_to_url($return, api_get_current_access_url_id());
} else {
//we are adding by default the access_url_user table with access_url_id = 1
UrlManager::add_user_to_url($return, 1);
}
if (!empty($email) && $send_mail) {
$recipient_name = api_get_person_name($firstName, $lastName, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if ($_configuration['multiple_access_urls']) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstName, $lastName)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $loginName ."\n". get_lang('Pass')." : ".stripslashes($original_password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
} else {
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstName, $lastName)).",\n\n".get_lang('YouAreReg')." ".api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $loginName ."\n". get_lang('Pass')." : ".stripslashes($original_password)."\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
@api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
// Add event to system log
$user_id_manager = api_get_user_id();
$user_info = api_get_user_info($return);
event_system(LOG_USER_CREATE, LOG_USER_ID, $return, api_get_utc_datetime(), $user_id_manager,null,$user_info);
event_system(LOG_USER_CREATE, LOG_USER_ID, $return, api_get_utc_datetime(), $user_id_manager, null, $user_info);
} else {
//echo "false - failed" ;
@ -419,26 +437,45 @@ class UserManager {
* @param array A series of additional fields to add to this user as extra fields (optional, defaults to null)
* @return boolean true if the user information was updated
*/
public static function update_user($user_id, $firstname, $lastname, $username, $password = null, $auth_source = null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, $creator_id = null, $hr_dept_id = 0, $extra = null, $language = 'english', $encrypt_method = '') {
public static function update_user($user_id, $firstname, $lastname, $username, $password = null, $auth_source = null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active, $creator_id = null, $hr_dept_id = 0, $extra = null, $language = 'english', $encrypt_method = '', $send_email = false, $reset_password = 0) {
global $_configuration;
$original_password = $password;
$user_info = api_get_user_info($user_id, false, true);
if ($reset_password == 0) {
$password = null;
$auth_source = $user_info['auth_source'];
} elseif($reset_password == 1) {
$original_password = $password = api_generate_password();
$auth_source = PLATFORM_AUTH_SOURCE;
} elseif($reset_password == 2) {
$password = $password;
$auth_source = PLATFORM_AUTH_SOURCE;
} elseif($reset_password == 3) {
$password = $password;
$auth_source = $auth_source;
}
if ($user_id != strval(intval($user_id))) return false;
if ($user_id === false) return false;
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
//Checking the user language
$languages = api_get_languages();
if (!in_array($language, $languages['folder'])) {
$language = api_get_setting('platformLanguage');
}
}
$sql = "UPDATE $table_user SET
lastname='".Database::escape_string($lastname)."',
firstname='".Database::escape_string($firstname)."',
username='".Database::escape_string($username)."',
language='".Database::escape_string($language)."',";
if (!is_null($password)) {
if($encrypt_method == '') {
if ($encrypt_method == '') {
$password = api_get_encrypted_password($password);
} else {
if ($_configuration['password_encryption'] === $encrypt_method ) {
@ -476,6 +513,25 @@ class UserManager {
$res = $res && self::update_extra_field_value($user_id,$fname,$fvalue);
}
}
if (!empty($email) && $send_email) {
$recipient_name = api_get_person_name($firstname, $lastname, null, PERSON_NAME_EMAIL_ADDRESS);
$emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
$sender_name = api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'), null, PERSON_NAME_EMAIL_ADDRESS);
$email_admin = api_get_setting('emailAdministrator');
if ($_configuration['multiple_access_urls']) {
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$url = api_get_access_url($access_url_id);
$emailbody = get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username . (($reset_password > 0) ? "\n". get_lang('Pass')." : ".stripslashes($original_password) : "") . "\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $url['url'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
} else {
$emailbody=get_lang('Dear')." ".stripslashes(api_get_person_name($firstname, $lastname)).",\n\n".get_lang('YouAreReg')." ". api_get_setting('siteName') ." ".get_lang('WithTheFollowingSettings')."\n\n".get_lang('Username')." : ". $username . (($reset_password > 0) ? "\n". get_lang('Pass')." : ".stripslashes($original_password) : "") . "\n\n" .get_lang('Address') ." ". api_get_setting('siteName') ." ". get_lang('Is') ." : ". $_configuration['root_web'] ."\n\n". get_lang('Problem'). "\n\n". get_lang('Formula').",\n\n".api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n". get_lang('Manager'). " ".api_get_setting('siteName')."\nT. ".api_get_setting('administratorTelephone')."\n" .get_lang('Email') ." : ".api_get_setting('emailAdministrator');
}
@api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
return $return;
}

Loading…
Cancel
Save