$user_info['firstname'], 'lastname' => $user_info['lastname'], 'status' => $status, 'admin' => $admin, 'email' => $user_info['email'], 'username' => $user_info['username'], 'language' => $language, 'password' => DEFAULT_PASSWORD, 'courses' => $user_info['courses'], 'profile_link' => $user_info['profile_link'], 'worldwide_bu' => $user_info['worlwide_bu'], 'manager' => $user_info['manager'], 'extra' => array( 'position_title' => $user_info['position_title'], 'country' => $user_info['country'], 'job_family' => $user_info['job_family'], 'country_bu' => $user_info['country_bu'], 'worldwide_bu' => $user_info['worldwide_bu'], 'profile_link' => $user_info['profile_link'], 'can_send_message' => $can_send_message, 'update_type' => 'external_logininfo') ); return $u; //Please return false if user does not exist //return false; } /** * Return an array with all user info * @param associative array with at least thes fields setted : firstname, lastname, status, email, login, password * @return mixed new user id - if the new user creation succeeds, false otherwise * */ function external_add_user($u) { //Setting default if (empty($u['password'])) $u['password'] = null; if (empty($u['status'])) $u['status'] = 5; if (!isset($u['official_code'])) $u['official_code'] = ''; if (!isset($u['language'])) $u['language'] = ''; if (!isset($u['phone'])) $u['phone'] = ''; if (!isset($u['picture_uri'])) $u['picture_uri'] = ''; if (!isset($u['auth_source'])) $u['auth_source'] = PLATFORM_AUTH_SOURCE; if (!isset($u['expiration_date'])) $u['expiration_date'] = '0000-00-00 00:00:00'; if (!isset($u['active'])) $u['active'] = 1; if (!isset($u['hr_dept_id'])) $u['hr_dept_id'] = 0; //id of responsible HR if (!isset($u['extra'])) $u['extra'] = null; if (!isset($u['encrypt_method'])) $u['encrypt_method'] = ''; $chamilo_uid = UserManager::create_user($u['firstname'], $u['lastname'], $u['status'], $u['email'], $u['username'], $u['password'], $u['official_code'], $u['language'], $u['phone'], $u['picture_uri'], $u['auth_source'], $u['expiration_date'], $u['active'], $u['hr_dept_id'], $u['extra'], $u['encrypt_method']); return $chamilo_uid; } /** * Update the user in chamilo database. It upgrade only info that is present in the * new_user array * * @param $new_user associative array with the value to upgrade * WARNING user_id key is MANDATORY * Possible keys are : * - firstname * - lastname * - username * - auth_source * - email * - status * - official_code * - phone * - picture_uri * - expiration_date * - active * - creator_id * - hr_dept_id * - extra : array of custom fields * - language * - courses : string of all courses code separated by '|' * - admin : boolean * @return boolean * @author ndiechburg * */ function external_update_user($new_user) { $old_user = api_get_user_info($new_user['user_id']); $u = array_merge($old_user, $new_user); $updated = UserManager::update_user($u['user_id'], $u['firstname'], $u['lastname'], $u['username'], null, $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 (isset($u['courses']) && !empty($u['courses'])) { $autoSubscribe = explode('|', $u['courses']); foreach ($autoSubscribe as $code) { if (CourseManager::course_exists($code)) { CourseManager::subscribe_user($u['user_id'], $code); } } } // Is User Admin ? //TODO decomments and check that user_is is not already in admin table /* if (isset($u['admin']) && $u['admin']){ $table = Database::get_main_table(TABLE_MAIN_ADMIN); $res = Database::query("SELECT * from $table WHERE user_id = ".$u['user_id']); } */ } ?>