Fixing a small css issue in the user class.
[elgg.git] / units / users / userdetails_actions.php
blobcda6f798bc840200b56f3308c523b8a55bdc6191
1 <?php
3 // Userdetails actions
4 global $USER, $CFG;
5 global $page_owner;
7 $id = optional_param('id',0,PARAM_INT);
8 $action = optional_param('action');
10 if (logged_on && !empty($action) && run("permissions:check", array("userdetails:change",$id))) {
12 switch ($action) {
14 // Update user details
15 case "userdetails:update":
16 $name = trim(optional_param('name'));
17 if (!empty($name)) {
18 $userdetails_ok = "yes";
19 if (strlen($name) > 64) {
20 $messages[] = __gettext("Your suggested name was too long. Please try something shorter.");
21 $userdetails_ok = "no";
24 $usertype = user_type($page_owner);
25 $email = trim(optional_param('email'));
26 if ($usertype == 'person' && !empty($email)) {
27 if (!validate_email($email)) {
28 $messages[] = __gettext("Your suggested email address $email doesn't appear to be valid.");
30 $userdetails_ok = "no";
31 } else {
32 $u = new StdClass;
33 $u->email = $email;
34 $u->ident = $id;
35 update_record('users',$u);
36 if ($USER->ident == $page_owner) {
37 $USER->email = $email;
38 $_SESSION['email'] = $email;
40 $messages[] = __gettext("Email address updated.");
44 $moderation = optional_param('moderation');
45 if (!empty($moderation) && in_array($moderation,array('yes','no','priv'))) {
46 set_field('users','moderation',$moderation,'ident',$id);
47 $messages[] = __gettext("Your moderation preferences have been changed.");
50 if (!$CFG->disable_publiccomments) {
51 $publiccomments = optional_param('publiccomments');
52 if ($usertype == 'person' && !empty($publiccomments)) {
53 if ($publiccomments == "yes") {
54 user_flag_set("publiccomments", "1", $id);
55 $messages[] = __gettext("Public comments and discussion set to 'on'.");
56 } else {
57 user_flag_unset("publiccomments",$id);
58 $messages[] = __gettext("Public comments and discussion set to 'off'.");
63 $receiveemails = optional_param('receiveemails');
64 if ($usertype == 'person' && isset($receiveemails)) {
65 if ($receiveemails == "yes") {
66 user_flag_set("emailreplies", "1", $id);
67 $messages[] = __gettext("Email comments and discussion set to 'on'.");
68 } else {
69 user_flag_unset("emailreplies",$id);
70 $messages[] = __gettext("Email comments and discussion set to 'off'.");
74 $receiveemails = optional_param('receivenotifications');
75 if ($usertype == 'person' && isset($receiveemails)) {
76 if ($receiveemails == "yes") {
77 user_flag_set("emailnotifications", "1", $id);
78 $messages[] = __gettext("Email notifications set to 'on'.");
79 } else {
80 user_flag_unset("emailnotifications",$id);
81 $messages[] = __gettext("Email notifications set to 'off'.");
85 if ($userdetails_ok == "yes") {
86 $messages[] = "Name updated.";
87 $u = new StdClass;
88 $u->name = $name;
89 $u->ident = $id;
90 update_record('users',$u);
91 if ($USER->ident == $page_owner) {
92 $USER->name = stripslashes($name);
93 $_SESSION['name'] = stripslashes($name);
95 } else {
96 $messages[] = __gettext("Details were not changed.");
101 $password1 = optional_param('password1');
102 $password2 = optional_param('password2');
104 if (!empty($password1) || !empty($password2)) {
105 if (($password1 == $password2)) {
106 if (strlen($password1) < 4 || strlen($password1) > 32) {
107 $messages[] = __gettext("Password not changed: Your password is either too short or too long. It must be between 4 and 32 characters in length.");
108 } else if (!preg_match("/^[a-zA-Z0-9]*$/i",$password1)) {
109 $messages[] = __gettext("Password not changed: Your password can only consist of letters or numbers.");
110 } else {
111 $messages[] = __gettext("Your password was updated.");
112 $u = new StdClass;
113 $u->password = md5($password1);
114 $u->ident = $page_owner;
115 update_record('users',$u);
117 } else {
118 $messages[] = __gettext("Password not changed: The password and its verification string did not match.");
121 break;