5 // Kill all old invitations
6 delete_records_select('invitations',"added < ?",array(time() - (86400 * 7)));
9 $sitename = $CFG->sitename
;
11 $action = optional_param('action');
14 // Add a new invite code
16 $invite = new StdClass
;
17 $invite->name
= trim(optional_param('invite_name'));
18 $invite->email
= trim(optional_param('invite_email'));
19 if (!empty($invite->name
) && !empty($invite->email
)) {
20 if (logged_on ||
($CFG->publicinvite
== true)) {
21 if (($CFG->maxusers
== 0 ||
(count_users('person') < $CFG->maxusers
))) {
22 if (validate_email(stripslashes($invite->email
))) {
23 $strippedname = stripslashes($invite->name
); // for the message text.
24 $invitations = count_records('invitations','email',$invite->email
);
25 if ($invitations == 0) {
26 if (!$account = get_record('users','email',$invite->email
)) {
27 $invite->code
= 'i' . substr(base_convert(md5(time() . $USER->username
), 16, 36), 0, 7);
28 $invite->added
= time();
29 $invite->owner
= $USER->ident
;
30 insert_record('invitations',$invite);
31 $url = url
. "_invite/join.php?invitecode=" . $invite->code
;
34 $greetingstext = sprintf(__gettext("Thank you for registering with %s."),$sitename);
35 $subjectline = sprintf(__gettext("%s account verification"),$sitename);
38 $invitetext = trim(optional_param('invite_text'));
39 if (!empty($invitetext)) {
40 $invitetext = __gettext("They included the following message:") . "\n\n----------\n" . $invitetext . "\n----------";
42 $greetingstext = $USER->name
. " " . __gettext("has invited you to join") ." $sitename, ". __gettext("a social network.") ."";
43 $subjectline = $USER->name
. " " . __gettext("has invited you to join") ." $sitename";
44 $from_email = $USER->email
;
46 $emailmessage = sprintf(__gettext("Dear %s,\n\n%s %s\n\nTo join, visit the following URL:\n\n\t%s\n\nYour email address has not been passed onto any third parties, and will be removed from our system within seven days.\n\nRegards,\n\nThe %s team."),$strippedname,$greetingstext,$invitetext,$url, $sitename);
47 $emailmessage = wordwrap($emailmessage);
48 $messages[] = sprintf(__gettext("Your invitation was sent to %s at %s. It will be valid for seven days."),$strippedname,$invite->email
);
49 email_to_user($invite,null,$subjectline,$emailmessage);
51 $messages[] = sprintf(__gettext("User %s already has that email address. Invitation not sent."),$account->username
);
54 $messages[] = __gettext("Someone with that email address has already been invited to the system. ");
57 $messages[] = __gettext("Invitation failed: The email address was not valid.");
60 $messages[] = __gettext("Error: This community has reached its maximum number of users.");
63 $messages[] = __gettext("Invitation failed: you are not logged in.");
66 $messages[] = __gettext("Invitation failed: you must specify both a name and an email address.");
69 // Join using an invitation
71 $name = trim(optional_param('join_name'));
72 $code = trim(optional_param('invitecode'));
73 $over13 = optional_param('over13');
74 $username = trim(optional_param('join_username'));
75 $password1 = trim(optional_param('join_password1'));
76 $password2 = trim(optional_param('join_password2'));
77 if (isset($name) && isset($code)) {
78 if (!($CFG->maxusers
== 0 ||
(count_users('person') < $CFG->maxusers
))) {
79 $messages[] = __gettext("Unfortunately this community has reached its account limit and you are unable to join at this time.");
83 $messages[] = __gettext("You must indicate that you are at least 13 years old to join.");
86 if (!$details = get_record('invitations','code',$code)) {
87 $messages[] = __gettext("Error! Invalid invite code.");
90 if ($password1 != $password2 ||
strlen($password1) < 6 ||
strlen($password2) > 16) {
91 $messages[] = __gettext("Error! Invalid password. Your passwords must match and be between 6 and 16 characters in length.");
94 if (!preg_match("/^[A-Za-z0-9]{3,12}$/",$username)) {
95 $messages[] = __gettext("Error! Your username must contain letters and numbers only, cannot be blank, and must be between 3 and 12 characters in length.");
98 $username = strtolower($username);
99 if (record_exists('users','username',$username)) {
100 $messages[] = __gettext("The username '$username' is already taken by another user. You will need to pick a different one.");
103 $displaypassword = $password1;
106 $u->password
= md5($password1);
107 $u->email
= $details->email
;
108 $u->username
= $username;
109 $u = plugin_hook("user","create",$u);
112 $ident = insert_record('users',$u);
114 // Calendar code is in the wrong place!
116 if(isset($function["calendar:init"])) {
119 insert_record('calendar',$c);
121 $owner = (int)$details->owner
;
122 if ($owner != -1) { // invited by someone - set up mutual friendship
126 insert_record('friends',$f);
129 insert_record('friends',$f);
131 // make them friend the news user
135 insert_record('friends',$f);
137 $u = plugin_hook("user","publish",$u);
139 $rssresult = run("weblogs:rss:publish", array($ident, false));
140 $rssresult = run("files:rss:publish", array($ident, false));
141 $rssresult = run("profile:rss:publish", array($ident, false));
142 $_SESSION['messages'][] = __gettext("Your account was created! You can now log in using the username and password you supplied. You have been sent an email containing these details for reference purposes.");
143 delete_records('invitations','code',$code);
144 email_to_user($u,null,sprintf(__gettext("Your %s account"),$sitename),
145 sprintf(__gettext("Thanks for joining %s!\n\nFor your records, your %s username and password are:\n\n\t")
146 .__gettext("Username: %s\n\tPassword: %s\n\nYou can log in at any time by visiting %s and entering these details into the login form.\n\n")
147 .__gettext("We hope you enjoy using the system.\n\nRegards,\n\nThe %s Team")
148 ,$sitename,$sitename,$username,$displaypassword,url
,$sitename));
149 header("Location: " . $CFG->wwwroot
);
156 // Request a new password
157 case "invite_password_request":
158 $username = optional_param('password_request_name');
159 if (!empty($username)) {
160 if ($user = get_record('users','username',trim($username),'user_type','person')) {
161 $pwreq = new StdClass
;
162 $pwreq->code
= 'i' . substr(base_convert(md5(time() . $username), 16, 36), 0, 7);
163 $pwreq->owner
= $user->ident
;
164 insert_record('password_requests',$pwreq);
165 $url = url
. "_invite/new_password.php?passwordcode=" . $pwreq->code
;
166 email_to_user($user,null,sprintf(__gettext("Verify your %s account password request"),$sitename),
167 sprintf(__gettext("A request has been received to generate your account at %s a new password.\n\n")
168 .__gettext("To confirm this request and receive a new password by email, please click the following link:\n\n\t%s\n\n")
169 .__gettext("Please let us know if you have any further problems.\n\nRegards,\n\nThe %s Team")
170 ,$sitename,$url,$sitename));
171 $messages[] = __gettext("Your verification email was sent. Please check your inbox.");
173 $messages[] = __gettext("No user with that username was found.");