| 13 |
$options = array(); |
$options = array(); |
| 14 |
$options['user']['email'] = t('Email Address*'); |
$options['user']['email'] = t('Email Address*'); |
| 15 |
$options['user']['password'] = t('Password'); |
$options['user']['password'] = t('Password'); |
| 16 |
|
$options['user']['roles'] = t('Roles'); |
| 17 |
return $options; |
return $options; |
| 18 |
} |
} |
| 19 |
|
|
| 56 |
$value = trim($data[$column_id]); |
$value = trim($data[$column_id]); |
| 57 |
} |
} |
| 58 |
|
|
| 59 |
|
if ($field_id == 'roles') { |
| 60 |
|
$value = user_user_import_roles_data($data[$column_id], $settings['roles_new']); |
| 61 |
|
} |
| 62 |
|
|
| 63 |
return $value; |
return $value; |
| 64 |
} |
} |
| 65 |
|
|
| 82 |
|
|
| 83 |
case UPDATE_REPLACE: |
case UPDATE_REPLACE: |
| 84 |
// update roles |
// update roles |
| 85 |
$account_add['roles'] = array(); |
if (!isset($account_add['roles'])) { |
| 86 |
|
$account_add['roles'] = array(); |
| 87 |
|
} |
| 88 |
|
|
| 89 |
foreach ($settings['roles'] as $rid => $role_set) { |
foreach ($settings['roles'] as $rid => $role_set) { |
| 90 |
if (!empty($role_set)) { |
if (!empty($role_set)) { |
| 151 |
$form['role_selection'] = array( |
$form['role_selection'] = array( |
| 152 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 153 |
'#title' => t('Role Assign'), |
'#title' => t('Role Assign'), |
|
'#description' => t("Select which role(s) imported users should be assigned. The role 'authenticated user' is assigned automatically."), |
|
| 154 |
'#weight' => -80, |
'#weight' => -80, |
| 155 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 156 |
'#collapsed' => $collapsed, |
'#collapsed' => $collapsed, |
| 157 |
); |
); |
| 158 |
|
|
| 159 |
$form['role_selection']['roles'] = array( |
$form['role_selection']['roles'] = array( |
| 160 |
|
'#title' => t('Assign Role(s) To All Users'), |
| 161 |
'#type' => 'checkboxes', |
'#type' => 'checkboxes', |
| 162 |
'#options' => $roles, |
'#options' => $roles, |
| 163 |
'#default_value' => $roles_selected, |
'#default_value' => $roles_selected, |
| 164 |
|
'#description' => t("Select which role(s) all imported users should be assigned. The role 'authenticated user' is assigned automatically."), |
| 165 |
|
|
| 166 |
|
); |
| 167 |
|
|
| 168 |
|
$form['role_selection']['roles_new'] = array( |
| 169 |
|
'#type' => 'checkbox', |
| 170 |
|
'#title' => t('Add New Roles'), |
| 171 |
|
'#default_value' => $import['options']['roles_new'], |
| 172 |
|
'#description' => t('Create imported role(s) that are not found and assign it to the user, in addition to any role(s) selected above. Warning: incorrect roles will be created if the incoming data includes typos.'), |
| 173 |
); |
); |
| 174 |
|
|
| 175 |
return; |
return; |
| 240 |
$uid = db_result(db_query("SELECT uid FROM {users} WHERE mail= '%s' LIMIT 1", $email)); |
$uid = db_result(db_query("SELECT uid FROM {users} WHERE mail= '%s' LIMIT 1", $email)); |
| 241 |
return $uid; |
return $uid; |
| 242 |
} |
} |
| 243 |
|
|
| 244 |
|
/** |
| 245 |
|
* Implementation of hook_user_import_after_save(). |
| 246 |
|
*/ |
| 247 |
|
function user_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) { |
| 248 |
|
/** |
| 249 |
|
* @todo change hook_user_import_after_save() so that all changes to data are returned and saved in one hit |
| 250 |
|
*/ |
| 251 |
|
user_save($account, array('contact' => $settings['contact'])); |
| 252 |
|
user_user_import_after_save_role($account, $settings['roles_new'], $account->roles, $fields['user']['roles']); |
| 253 |
|
return; |
| 254 |
|
} |
| 255 |
|
|
| 256 |
|
function user_user_import_roles_data($data, $new_roles_allowed) { |
| 257 |
|
|
| 258 |
|
if (empty($data)) return; |
| 259 |
|
$values = explode( ',', $data); |
| 260 |
|
//var_dump($values); |
| 261 |
|
// check if any roles are specified that don't already exist |
| 262 |
|
$existing_roles = user_roles(); |
| 263 |
|
|
| 264 |
|
foreach($values as $piece) { |
| 265 |
|
$role = trim($piece); |
| 266 |
|
$unrecognised = array(); |
| 267 |
|
|
| 268 |
|
if (!empty($role)) { |
| 269 |
|
// only add if role is recognized or adding new roles is allowed |
| 270 |
|
if (empty($new_roles_allowed) && !array_search($role, $existing_roles)) { |
| 271 |
|
$unrecognised[] = $role; |
| 272 |
|
} |
| 273 |
|
else { |
| 274 |
|
$roles[] = $role; |
| 275 |
|
} |
| 276 |
|
} |
| 277 |
|
|
| 278 |
|
} |
| 279 |
|
|
| 280 |
|
if (!empty($unrecognised)) { |
| 281 |
|
user_import_errors(t('The following unrecognised roles were specified: ') . implode(',', $unrecognised)); |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
return $roles; |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
|
| 288 |
|
function user_user_import_after_save_role($account, $new_roles_allowed, $account_roles, $roles) { |
| 289 |
|
|
| 290 |
|
$existing_roles = user_roles(); |
| 291 |
|
|
| 292 |
|
// if roles were specified, add to existing roles |
| 293 |
|
$assign_roles = array(); |
| 294 |
|
|
| 295 |
|
if (is_array($roles) && !empty($roles)) { |
| 296 |
|
|
| 297 |
|
foreach ($roles as $role) { |
| 298 |
|
|
| 299 |
|
if (!empty($role)) { |
| 300 |
|
|
| 301 |
|
$key = array_search($role, $existing_roles); |
| 302 |
|
|
| 303 |
|
if (!empty($new_roles_allowed) && empty($key)) { |
| 304 |
|
db_query("INSERT INTO {role} (name) VALUES ('%s')", $role); |
| 305 |
|
$key = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s' LIMIT 1", $role)); |
| 306 |
|
$existing_roles[$key] = $role; |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
$assign_roles[$key] = $role; |
| 310 |
|
} |
| 311 |
|
} |
| 312 |
|
|
| 313 |
|
$need_update = FALSE; |
| 314 |
|
|
| 315 |
|
foreach ($assign_roles as $key => $role) { |
| 316 |
|
if (!isset($account_roles[$key])) { |
| 317 |
|
$need_update = TRUE; |
| 318 |
|
$account_roles[$key] = $role; |
| 319 |
|
} |
| 320 |
|
} |
| 321 |
|
|
| 322 |
|
if ($need_update) { |
| 323 |
|
user_save($account, array('roles' => $account_roles)); |
| 324 |
|
} |
| 325 |
|
} |
| 326 |
|
|
| 327 |
|
return; |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
|
| 331 |
|
|