summaryrefslogtreecommitdiff
blob: 8603906216081a66850e323bbcf437e178784972 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
function init_invite(&$S) {
	if (!$S['conf']['invite']) return '404';
	if (!isset($S['user'])) return 'login';
	if ($S['conf']['invite'] == 'admin' && !$S['user']->has_flag('a')) return '404';
	return array('title' => 'Invite');
}
function body_invite(&$S) {
	if (isset($_REQUEST['emails'])) {
		echo '<h3>Inviting Users</h3>';
		$emails=explode("\n", $_REQUEST['emails']);
		foreach ($emails as $email) {
			// TODO proper checking that user and registrationtoken don't exist for this email to avoid errors
			$email=trim($email);
			if (strlen($email) == 0) {
				continue;
			}
			if (!Validate::email($email)) {
				echo 'Email address "'.htmlentities($email).'" invalid<br/>';
				continue;
			}
			$token=sql_registrationtoken::create();
			$token->email=$email;
			$token->expire=time()+24*3600; // 24 hour shelf life (we're not checking currently)
			$token->owner=$S['user']->id;
			$token->write();
			xhtmlemail($email, null, $S['conf']['title'].' invitation', htmlentities($S['user']->name).' has invited you to create an account for '.$S['conf']['title'].'.  To create an account, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>');
			echo 'Invited '.htmlentities($email).'<br/>';
		}
		echo '<a href="'.url('invite').'">Send more invitations</a>';
	} else {
		echo '<h3>Invite Users</h3><form action="'.url('invite').'" method="post">Email addresses to send invitations to: (one per line)<br/><textarea name="emails"></textarea><br/><input type="submit" value="Send Invitations" /></form>';
	}
}
?>