Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
useradd.php
Go to the documentation of this file.
1 <?php
9 elgg_make_sticky_form('useradd');
10 
11 // Get variables
12 $username = get_input('username');
13 $password = get_input('password', null, false);
14 $password2 = get_input('password2', null, false);
15 $email = get_input('email');
16 $name = get_input('name');
17 
18 // This param is not included in the useradd form by default,
19 // but it allows sites to easily add the feature if necessary.
20 $language = get_input('language', elgg_get_config('language'));
21 
22 $admin = get_input('admin');
23 if (is_array($admin)) {
24  $admin = $admin[0];
25 }
26 
27 $autogen_password = get_input('autogen_password');
28 if ($autogen_password) {
31 }
32 
33 // no blank fields
34 if ($username == '' || $password == '' || $password2 == '' || $email == '' || $name == '') {
35  register_error(elgg_echo('register:fields'));
37 }
38 
39 if (strcmp($password, $password2) != 0) {
40  register_error(elgg_echo('RegistrationException:PasswordMismatch'));
42 }
43 
44 // For now, just try and register the user
45 try {
47 
48  if ($guid) {
49  $new_user = get_entity($guid);
50  if ($new_user && $admin && elgg_is_admin_logged_in()) {
51  $new_user->makeAdmin();
52  }
53 
54  elgg_clear_sticky_form('useradd');
55 
56  $new_user->admin_created = TRUE;
57  // @todo ugh, saving a guid as metadata!
58  $new_user->created_by_guid = elgg_get_logged_in_user_guid();
59 
60  // The user language is set also by register_user(), but it defaults to
61  // language of the current user (admin), so we need to fix it here.
62  $new_user->language = $language;
63 
64  $subject = elgg_echo('useradd:subject', array(), $new_user->language);
65  $body = elgg_echo('useradd:body', array(
66  $name,
69  $username,
70  $password,
71  ), $new_user->language);
72 
73  notify_user($new_user->guid, elgg_get_site_entity()->guid, $subject, $body);
74 
75  system_message(elgg_echo("adduser:ok", array(elgg_get_site_entity()->name)));
76  } else {
77  register_error(elgg_echo("adduser:bad"));
78  }
79 } catch (RegistrationException $r) {
80  register_error($r->getMessage());
81 }
82 
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_get_site_entity($site_guid=0)
Get an entity (default is current site)
Definition: sites.php:18
$r
$name
Definition: useradd.php:16
if(!$site) if(!($site instanceof ElggSite)) $site url
$subject
Definition: exceptions.php:25
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:60
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$admin
Definition: useradd.php:22
$username
Definition: useradd.php:12
$site name
$guid
Removes an admin notice.
register_user($username, $password, $name, $email, $allow_multiple_emails=false)
Registers a user, returning false if the username already exists.
Definition: users.php:316
register_error($error)
Display an error on next page load.
Definition: elgglib.php:452
$password2
Definition: useradd.php:14
$email
Definition: useradd.php:15
if(is_array($admin)) $autogen_password
Definition: useradd.php:27
$language
Definition: useradd.php:20
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
const REFERER
Definition: elgglib.php:2029
elgg_make_sticky_form($form_name)
Save form submission data (all GET and POST vars) into a session cache.
Definition: input.php:103
forward($location="", $reason= 'system')
Forward to $location.
Definition: elgglib.php:93
notify_user($to, $from, $subject, $message, array $params=array(), $methods_override="")
Notify a user via their preferences.
generate_random_cleartext_password()
Generate a random 12 character clear text password.
Definition: users.php:189
elgg_clear_sticky_form($form_name)
Remove form submission data from the session.
Definition: input.php:119
system_message($message)
Display a system message on next page load.
Definition: elgglib.php:438
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Definition: sessions.php:42
$password
Definition: useradd.php:13
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204