switch ($cmd) { case 'rqResetAllPasswords': $dialogBox->question(get_lang('Do you really want to reset all the passwords ?') . '<br />' . '<small>' . get_lang('The platform administrators and course creators password will remain unchanged') . '</small>' . '<br />'); $dialogBox->form(' <form method="post" action="' . claro_htmlspecialchars($_SERVER['PHP_SELF']) . '">' . '<input type="hidden" name="cmd" value="exResetAllPasswords" />' . '<input id="sendEmail" type="checkbox" name="sendEmail" value="yes" checked="checked" />' . '<label for="sendEmail">' . get_lang('send new password by email') . '</label>' . '<br />' . '<small>' . get_lang('Only the users with a valid address will receive their password by email') . '</small>' . '<br />' . '<input type="submit" value="' . get_lang('Yes') . '" />' . claro_html_button($_SERVER['PHP_SELF'], get_lang('Cancel')) . '</form>'); $dialogBox->warning('<em>' . get_lang('This may take some time, please wait until the end of the process...') . '</em>'); break; case 'exResetAllPasswords': $userList = getAllStudentUserId(); $failedMailList = array(); $failedList = array(); $sendEmail = isset($_REQUEST['sendEmail']) && $_REQUEST['sendEmail'] ? true : false; foreach ($userList as $user) { $mailSent = FALSE; $userInfo = user_get_properties($user['id']); if (!$userInfo['isPlatformAdmin'] && !$userInfo['isCourseCreator']) { $userInfo['password'] = mk_password(8); if (user_set_properties($user['id'], array('password' => $userInfo['password']))) { if ($sendEmail && user_send_registration_mail($user['id'], $userInfo)) { $mailSent = TRUE; } } else { $failedList[] = $userInfo; } } if ($sendEmail && !$mailSent) { $failedMailList[] = $userInfo; } } if (empty($failedList)) { $dialogBox->success(get_lang('Password changed successfully for all concerned users')); } else {
/** * Import users in course. * * @author Dimitri Rambout <*****@*****.**> * @param $courseId id of the course * * @return boolean */ public function importUsersInCourse($userList, $courseId, $canCreateUser = true, $enrollUserInCourse = true, $class_id = 0, $sendEmail = 0) { if (empty($this->data)) { return false; } if (!(isset($userList) && count($userList))) { return false; } $logs = array(); $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_user = $tbl_mdb_names['user']; $tbl_course_user = $tbl_mdb_names['rel_course_user']; $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_group_rel_team_user = $tbl_cdb_names['group_rel_team_user']; $groupsImported = array(); $userInfo = array(); foreach ($userList as $user_id) { if (!isset($this->data[$user_id])) { $logs['errors'][] = get_lang('Unable to find the user in the csv'); } else { $userInfo['username'] = $this->data[$user_id]['username']; $userInfo['firstname'] = $this->data[$user_id]['firstname']; $userInfo['lastname'] = $this->data[$user_id]['lastname']; $userInfo['email'] = isset($this->data[$user_id]['email']) && !empty($this->data[$user_id]['email']) ? $this->data[$user_id]['email'] : ''; $userInfo['password'] = isset($this->data[$user_id]['password']) && !empty($this->data[$user_id]['password']) ? $this->data[$user_id]['password'] : mk_password(8); $userInfo['officialCode'] = isset($this->data[$user_id]['officialCode']) ? $this->data[$user_id]['officialCode'] : ''; if (isset($this->data[$user_id]['groupName'])) { $groupNames = $this->data[$user_id]['groupName']; } else { $groupNames = null; } //check user existe if not create is asked $resultSearch = user_search(array('username' => $userInfo['username']), null, true, true); if (empty($resultSearch)) { if (!$canCreateUser) { $userId = 0; $logs['errors'][] = get_lang('Unable to create user %username, option is disabled in configuration', array('%username' => $userInfo['username'])); } else { $userId = user_create($userInfo); if ($userId != 0) { $logs['success'][] = get_lang('User profile %username created successfully', array('%username' => $userInfo['username'])); if ($sendEmail) { user_send_registration_mail($userId, $userInfo); } } else { $logs['errors'][] = get_lang('Unable to create user %username', array('%username' => $userInfo['username'])); } } } else { $userId = $resultSearch[0]['uid']; $logs['errors'][] = get_lang('User %username not created because it already exists in the database', array('%username' => $userInfo['username'])); } if ($userId == 0) { $logs['errors'][] = get_lang('Unable to add user %username in this course', array('%username' => $userInfo['username'])); } else { if (!$enrollUserInCourse) { $logs['errors'][] = get_lang('Unable to add user %username in this course, option is disabled in configuration', array('%username' => $userInfo['username'])); } else { if (!user_add_to_course($userId, $courseId, false, false, null)) { $logs['errors'][] = get_lang('Unable to add user %username in this course', array('%username' => $userInfo['username'])); } else { $logs['success'][] = get_lang('User %username added in course %courseId', array('%username' => $userInfo['username'], '%courseId' => $courseId)); //join class if needed if ($class_id) { if (!($return = user_add_to_class($userId, $class_id))) { $logs['errors'][] = get_lang('Unable to add %username in the selected class', array('%username' => $userInfo['username'])); } else { $logs['success'][] = get_lang('User %username added in the selected class', array('%username' => $userInfo['username'])); } } //join group $groups = explode(',', $groupNames); if (is_array($groups)) { foreach ($groups as $group) { $group = trim($group); if (!empty($group)) { $groupsImported[$group][] = $userId; } } } } } } } } foreach ($groupsImported as $group => $users) { $GLOBALS['currentCourseRepository'] = claro_get_course_path($courseId); $groupId = create_group($group, null); if ($groupId == 0) { $logs['errors'][] = get_lang('Unable to create group %groupname', array('%groupname' => $group)); } else { foreach ($users as $userId) { $sql = "INSERT INTO `" . $tbl_group_rel_team_user . "`\n SET user = "******",\n team = " . (int) $groupId; if (!claro_sql_query($sql)) { $logs['errors'][] = get_lang('Unable to add user in group %groupname', array('%groupname' => $group)); } } } } return $logs; }