Minor - format code

1.9.x
Julio Montoya 11 years ago
parent d5f6978964
commit e6b8e7133f
  1. 38
      main/admin/user_import.php
  2. 39
      main/inc/lib/usermanager.lib.php

@ -114,26 +114,45 @@ function complete_missing_data($user) {
* @return void
* @uses global variable $inserted_in_course, which returns the list of courses the user was inserted in
*/
function save_data($users) {
function save_data($users)
{
global $inserted_in_course;
// Not all scripts declare the $inserted_in_course array (although they should).
if (!isset($inserted_in_course)) {
$inserted_in_course = array();
}
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
$send_mail = $_POST['sendMail'] ? 1 : 0;
$send_mail = $_POST['sendMail'] ? true : false;
if (is_array($users)) {
foreach ($users as $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'], $user['language'], $user['PhoneNumber'], '', $user['AuthSource'], null, 1, 0, null, null, $send_mail);
$user_id = UserManager :: create_user(
$user['FirstName'],
$user['LastName'],
$user['Status'],
$user['Email'],
$user['UserName'],
$user['Password'],
$user['OfficialCode'],
$user['language'],
$user['PhoneNumber'],
'',
$user['AuthSource'],
null,
1,
0,
null,
null,
$send_mail
);
if (!is_array($user['Courses']) && !empty($user['Courses'])) {
$user['Courses'] = array($user['Courses']);
}
if (is_array($user['Courses'])) {
foreach ($user['Courses'] as $index => $course) {
if (CourseManager :: course_exists($course)) {
CourseManager :: subscribe_user($user_id, $course,$user['Status']);
foreach ($user['Courses'] as $course) {
if (CourseManager::course_exists($course)) {
CourseManager::subscribe_user($user_id, $course, $user['Status']);
$course_info = CourseManager::get_course_information($course);
$inserted_in_course[$course] = $course_info['title'];
}
@ -144,13 +163,14 @@ function save_data($users) {
if ($vcourse['code'] == $course) {
// Ignore, this has already been inserted.
} else {
CourseManager :: subscribe_user($user_id, $vcourse['code'],$user['Status']);
CourseManager :: subscribe_user($user_id, $vcourse['code'], $user['Status']);
$inserted_in_course[$vcourse['code']] = $vcourse['title'];
}
}
}
}
}
if (!empty($user['ClassName'])) {
$class_id = ClassManager :: get_class_id($user['ClassName']);
ClassManager :: add_user($user_id, $class_id);
@ -160,11 +180,11 @@ function save_data($users) {
global $extra_fields;
// We are sure that the extra field exists.
foreach($extra_fields as $extras) {
foreach ($extra_fields as $extras) {
if (isset($user[$extras[1]])) {
$key = $extras[1];
$value = $user[$extras[1]];
UserManager::update_extra_field_value($user_id, $key,$value);
UserManager::update_extra_field_value($user_id, $key, $value);
}
}
}

@ -63,8 +63,25 @@ class UserManager
* @assert ('Sam','Gamegie',5,'sam@example.com','jo','jo') > 1
* @assert ('Pippin','Took',null,null,'jo','jo') === false
*/
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)
{
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;
@ -163,7 +180,6 @@ class UserManager
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');
@ -185,17 +201,12 @@ class UserManager
$values["prior_lang"] = null;
EventsDispatcher::events('user_registration', $values);
} else {
@api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
api_mail_html($recipient_name, $email, $emailsubject, $emailbody, $sender_name, $email_admin);
}
/* ENDS MANAGE EVENT WITH MAIL */
}
// Add event to system log
$user_id_manager = api_get_user_id();
event_system(LOG_USER_CREATE, LOG_USER_ID, $return);
} else {
$return = false;
return api_set_failure('error inserting in Database');
}
@ -2136,7 +2147,7 @@ class UserManager
// Checking session visibility
$visibility = api_get_session_visibility($session_id, null, $ignore_visibility_for_admins);
switch ($visibility) {
case SESSION_VISIBLE_READ_ONLY:
case SESSION_VISIBLE:
@ -2144,7 +2155,7 @@ class UserManager
break;
case SESSION_INVISIBLE:
continue(2);
}
}
$categories[$row['session_category_id']]['sessions'][$row['id']]['session_name'] = $row['name'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['session_id'] = $row['id'];
@ -2153,12 +2164,12 @@ class UserManager
$categories[$row['session_category_id']]['sessions'][$row['id']]['nb_days_access_before_beginning'] = $row['nb_days_access_before_beginning'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['nb_days_access_after_end'] = $row['nb_days_access_after_end'];
$categories[$row['session_category_id']]['sessions'][$row['id']]['courses'] = UserManager::get_courses_list_by_session($user_id, $row['id']);
}
}
return $categories;
}
/**

Loading…
Cancel
Save