4 // Account registration and verification form. This form can be called
7 // 1. ?first_name=FIRST_NAME&last_name=LAST_NAME&email=EMAIL...
9 // Called by the form at the bottom of the page to register a new
10 // account. If any required fields are missing, AddPerson() will fault
11 // and the specified fields will be highlighted. Otherwise, the
12 // account is registered (but not enabled), and VerifyPerson() sends
13 // the user a link back to this page.
15 // 2. ?id=PERSON_ID&key=VERIFICATION_KEY...
17 // Sent to the specified user by VerifyPerson(). If the user receives
18 // the message, then the registered e-mail address is considered
19 // valid, and registration can continue. VerifyPerson() is called
20 // again, and sends the current PI(s) (and support if the user is
21 // requesting a PI role) a link to the user's Account Details page to
22 // enable the account.
24 // Mark Huang <mlhuang@cs.princeton.edu>
25 // Copyright (C) 2007 The Trustees of Princeton University
30 // Get session and API handles
31 require_once 'plc_session.php';
32 global $plc, $api, $adm;
34 // Get sorting functions
35 require_once 'plc_sorts.php';
38 require_once 'plc_drupal.php';
39 drupal_set_title('Account Registration');
40 include 'plc_header.php';
42 // Drupalish, but does not use Drupal itself to generate the form
44 $form['first_name'] = array('title' => 'First name', 'required' => TRUE,
45 'maxlength' => 60, 'size' => 15);
46 $form['last_name'] = array('title' => 'Last name', 'required' => TRUE,
47 'maxlength' => 60, 'size' => 15);
48 $form['title'] = array('title' => 'Title', 'required' => FALSE,
49 'maxlength' => 60, 'size' => 5);
50 $form['phone'] = array('title' => 'Telephone', 'required' => FALSE,
51 'maxlength' => 60, 'size' => 20);
52 $form['email'] = array('title' => 'E-mail', 'required' => TRUE,
53 'maxlength' => 60, 'size' => 30);
54 $form['password'] = array('title' => 'Password', 'required' => TRUE,
55 'maxlength' => 60, 'size' => 20);
56 $form['site_ids'] = array('title' => 'Site', 'required' => TRUE);
57 $form['roles'] = array('title' => 'Additional Roles', 'required' => FALSE);
59 //////////////////// additional messages
60 $form['email']['comment'] = <<< EOF
61 Your <b>E-mail</b> address must be able to receive e-mail and will be
62 used as your $PLC_NAME username
65 $form['site_ids']['comment'] = <<< EOF
66 Select the site where you belong
69 $form['roles']['comment'] = <<< EOF
70 Do not select the <b>Principal Investigator</b> or <b>Technical
71 Contact</b> roles unless you have spoken with the current PI of your
72 site, and you intend to assume either or both of these roles.
73 <br> Use Command-Clic to unselect or for multiple selection
79 foreach ($form as $name => $item) {
80 if (!empty($_REQUEST[$name])) {
81 $person[$name] = $_REQUEST[$name];
85 // Filter out "Select a site"
86 if (!empty($person['site_ids'])) {
87 $person['site_ids'] = array_filter($person['site_ids'],
88 create_function('$site_id', 'return intval($site_id) > 0;'));
91 if (!empty($person)) {
92 // Look for missing/blank entries
94 foreach ($form as $name => $item) {
95 if ($item['required'] && empty($person[$name])) {
96 $missing[] = $item['title'];
99 if (!empty($missing)) {
101 foreach ($missing as $field) {
102 $error .= "<li>$field field is required.</li>";
108 // N.B.: site_ids and roles are ignored by AddPerson()
109 $person_id = $adm->AddPerson($person);
110 $error = $adm->error();
116 // Add person to requested sites
117 foreach ($person['site_ids'] as $site_id) {
118 $adm->AddPersonToSite($person_id, intval($site_id));
119 $adm->SetPersonPrimarySite($person_id, intval($site_id));
122 // Add requested roles. Always add the user role.
123 $adm->AddRoleToPerson('user', $person_id);
124 if (!empty($person['roles'])) {
125 foreach ($person['roles'] as $role) {
126 $adm->AddRoleToPerson($role, $person_id);
130 // Send an e-mail containing a link back to this page, which will
131 // verify the given e-mail address as valid. PIs can still create
132 // and enable accounts on behalf of their users, they just have to
133 // find and enable the accounts manually after registering them.
134 $adm->VerifyPerson($person_id);
136 // Disable submit button
137 $person['person_id'] = $person_id;
140 $error = $adm->error();
143 if (!empty($error)) {
144 print '<div class="messages error">' . $error . '</div>';
146 print '<div class="messages status">Your registration request has been received. An e-mail has been sent to ';
147 print $person['email'];
148 print ' with further instructions.</div>';
152 $PLC_NAME = htmlspecialchars(PLC_NAME);
154 // E-mail address verified, go ahead and notify the PI (and possibly
155 // support if a PI role was requested) that a registration request was
157 if (!empty($_REQUEST['id']) && !empty($_REQUEST['key'])) {
158 $person_id = intval($_REQUEST['id']);
159 if ($adm->VerifyPerson($person_id, $_REQUEST['key']) != 1) {
160 print '<div class="messages error">' . $adm->error() . '.</div>';
162 $persons = $adm->GetPersons(array($person_id));
163 $person = $persons[0];
165 // Remove the password field from the form so that it is not
166 // highlighted as missing.
167 unset($form['password']);
169 print '<div class="messages status">';
170 print 'Your e-mail address has been verified. ';
171 print 'The PI(s) at your site have been notified of your account registration ';
173 if (in_array('pi', $person['roles'])) {
174 $support = PLC_MAIL_SUPPORT_ADDRESS;
175 print " and should contact <a href=\"mailto:$support\">$PLC_NAME Support <$support></a>. ";
176 print " $PLC_NAME Support will enable your account if authorized by your PI(s).";
178 print ' and are responsible for enabling your account.';
185 $self = $_SERVER['PHP_SELF'];
186 if (!empty($_SERVER['QUERY_STRING'])) {
187 $self .= "?" . $_SERVER['QUERY_STRING'];
193 // cannot register with foreign site
194 $adm->GetSites(array('is_public' => TRUE, 'peer_id' => NULL), array('site_id', 'name','enabled','peer_id'));
198 list($sites, $roles) = $adm->commit();
200 // Alphabetize sites by name
203 // Prepend invalid site to beginning of list to force user to select a site
204 $sites = array_merge(array(array('site_id' => -1, 'name' => 'Select a site', 'enabled' => TRUE)), $sites);
206 // Drop down selection box for each site
207 function site_option($site) {
210 $site_id = $site['site_id'];
212 if (!empty($person['site_ids']) && in_array($site_id, $person['site_ids'])) {
213 $selected = 'selected="selected"';
218 $option = "<option value=\"$site_id\" $selected";
219 if ( ! $site['enabled'] )
220 $option .= " disabled='disabled'";
222 $option .= htmlspecialchars($site['name']);
223 # Safari/IE do not implement disabled correctly
224 if ( ! $site['enabled'] )
225 $option .= " (pending registration)";
226 $option .= "</option>";
229 $site_options = implode("\n", array_map('site_option', $sites));
231 // Do not tempt users to register for the admin role. Administrators
232 // should register normally, then be granted the admin role by another
233 // admin. Also, all accounts should have the user role (see above).
234 foreach ($roles as $i => $role) {
235 if ($role['name'] == 'admin' || $role['name'] == 'user') {
241 global $standard_roles;
242 $standard_roles = array('user' => 'User',
243 'pi' => 'Principal Investigator',
244 'tech' => 'Technical Contact',
245 'admin' => 'Administrator');
247 // Drop down selection box for each role
248 function role_option($role) {
249 global $standard_roles, $selected_roles;
251 $name = $role['name'];
253 if (!empty($person['roles']) && in_array($name, $person['roles'])) {
254 $selected = 'selected="selected"';
259 $display = array_key_exists($name, $standard_roles) ? $standard_roles[$name] : $name;
261 $option = "<option value=\"$name\" $selected>";
262 $option .= htmlspecialchars($display);
263 $option .= "</option>";
266 $role_options = implode("\n", array_map('role_option', $roles));
268 $self = $_SERVER['PHP_SELF'];
269 if (!empty($_SERVER['QUERY_STRING'])) {
270 $self .= "?" . $_SERVER['QUERY_STRING'];
274 <div class="content">
276 <form action="$self" method="post">
278 <table border="0" cellpadding="5" cellspacing="0">
281 foreach ($form as $name => $item) {
283 if ( ! empty($item['comment'])) {
284 $comment=$item['comment'];
285 print "<tr><td colspan=2> </td></tr>";
286 print "<tr><td colspan=2> $comment: </td></tr>";
289 $title = $item['title'];
290 $required = $item['required'] ? '<span class="form-required" title="This field is required.">*</span>' : "";
291 $class = $item['required'] ? "required" : "";
292 if ($item['required'] && !empty($person) && empty($person[$name])) {
299 <td><label class="$class" for="edit-$name">$title: $required</label></td>\n
307 <td><select name="site_ids[]" id="edit-site_ids" class="form-select $class">
315 <td><select name="roles[]" multiple="multiple" id="edit-roles" class="form-select $class">
322 $maxlength = $item['maxlength'];
323 $size = $item['size'];
324 $value = !empty($person[$name]) ? $person[$name] : "";
325 $type = $name == 'password' ? "password" : "text";
327 <td><input type="$type" maxlength="$maxlength" name="$name" id="edit-$name" size="$size" value="$value" class="form-text $class"></td>\n
335 // Do not allow resubmits
336 if (empty($person['person_id'])) {
337 print '<tr><td colspan=2><input type="submit" name="op" value="Register" class="form-submit" /></td></tr>';
347 include 'plc_footer.php';