Elgg  Version 1.11
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 $admin = get_input('admin');
19 if (is_array($admin)) {
20  $admin = $admin[0];
21 }
22 
23 // no blank fields
24 if ($username == '' || $password == '' || $password2 == '' || $email == '' || $name == '') {
25  register_error(elgg_echo('register:fields'));
27 }
28 
29 if (strcmp($password, $password2) != 0) {
30  register_error(elgg_echo('RegistrationException:PasswordMismatch'));
32 }
33 
34 // For now, just try and register the user
35 try {
37 
38  if ($guid) {
39  $new_user = get_entity($guid);
40  if ($new_user && $admin && elgg_is_admin_logged_in()) {
41  $new_user->makeAdmin();
42  }
43 
44  elgg_clear_sticky_form('useradd');
45 
46  $new_user->admin_created = TRUE;
47  // @todo ugh, saving a guid as metadata!
48  $new_user->created_by_guid = elgg_get_logged_in_user_guid();
49 
50  $subject = elgg_echo('useradd:subject', array(), $new_user->language);
51  $body = elgg_echo('useradd:body', array(
52  $name,
55  $username,
56  $password,
57  ), $new_user->language);
58 
59  notify_user($new_user->guid, elgg_get_site_entity()->guid, $subject, $body);
60 
61  system_message(elgg_echo("adduser:ok", array(elgg_get_site_entity()->name)));
62  } else {
63  register_error(elgg_echo("adduser:bad"));
64  }
65 } catch (RegistrationException $r) {
66  register_error($r->getMessage());
67 }
68 
elgg_get_site_entity($site_guid=0)
Get an entity (default is current site)
Definition: sites.php:18
$r
$name
Definition: useradd.php:16
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$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_clear_sticky_form($form_name)
Clear the sticky form cache.
Definition: input.php:119
$admin
Definition: useradd.php:18
$username
Definition: useradd.php:12
$guid
Removes an admin notice.
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
register_user($username, $password, $name, $email, $allow_multiple_emails=false)
Registers a user, returning false if the username already exists.
Definition: users.php:316
$password2
Definition: useradd.php:14
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
$email
Definition: useradd.php:15
const REFERER
Definition: elgglib.php:1995
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
$site name
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
if(!$site) if(!($site instanceof ElggSite)) $site url
notify_user($to, $from, $subject, $message, array $params=array(), $methods_override="")
Notify a user via their preferences.
elgg_make_sticky_form($form_name)
Load all the GET and POST variables into the sticky form cache.
Definition: input.php:103
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:382