5 // Account registration and verification form. This form can be called
8 // 1. ?first_name=FIRST_NAME&last_name=LAST_NAME&email=EMAIL...
10 // Called by the form at the bottom of the page to register a new
11 // account. If any required fields are missing, AddPerson() will fault
12 // and the specified fields will be highlighted. Otherwise, the
13 // account is registered (but not enabled), and VerifyPerson() sends
14 // the user a link back to this page.
16 // 2. ?id=PERSON_ID&key=VERIFICATION_KEY...
18 // Sent to the specified user by VerifyPerson(). If the user receives
19 // the message, then the registered e-mail address is considered
20 // valid, and registration can continue. VerifyPerson() is called
21 // again, and sends the current PI(s) (and support if the user is
22 // requesting a PI role) a link to the user's Account Details page to
23 // enable the account.
25 // Mark Huang <mlhuang@cs.princeton.edu>
26 // Copyright (C) 2007 The Trustees of Princeton University
31 // Get session and API handles
32 require_once 'plc_session.php';
33 global $plc, $api, $adm;
36 require_once 'plc_drupal.php';
37 drupal_set_title('Account Registration');
38 include 'plc_header.php';
40 // Drupalish, but does not use Drupal itself to generate the form
42 $form['first_name'] = array('title' => 'First name', 'required' => TRUE,
43 'maxlength' => 60, 'size' => 15);
44 $form['last_name'] = array('title' => 'Last name', 'required' => TRUE,
45 'maxlength' => 60, 'size' => 15);
46 $form['title'] = array('title' => 'Title', 'required' => FALSE,
47 'maxlength' => 60, 'size' => 5);
48 $form['phone'] = array('title' => 'Telephone', 'required' => FALSE,
49 'maxlength' => 60, 'size' => 20);
50 $form['email'] = array('title' => 'E-mail', 'required' => TRUE,
51 'maxlength' => 60, 'size' => 30);
52 $form['password'] = array('title' => 'Password', 'required' => TRUE,
53 'maxlength' => 60, 'size' => 20);
54 $form['site_ids'] = array('title' => 'Site', 'required' => TRUE);
55 $form['roles'] = array('title' => 'Additional Roles', 'required' => FALSE);
57 //////////////////// additional messages
58 $form['email']['comment'] = <<< EOF
59 Your <b>E-mail</b> address must be able to receive e-mail and will be
60 used as your $PLC_NAME username
63 $form['site_ids']['comment'] = <<< EOF
64 Select the site where you belong
67 $form['roles']['comment'] = <<< EOF
68 Do not select the <b>Principal Investigator</b> or <b>Technical
69 Contact</b> roles unless you have spoken with the current PI of your
70 site, and you intend to assume either or both of these roles.
71 <br> Use Command-Clic to unselect or for multiple selection
77 foreach ($form as $name => $item) {
78 if (!empty($_REQUEST[$name])) {
79 $person[$name] = $_REQUEST[$name];
83 // Filter out "Select a site"
84 if (!empty($person['site_ids'])) {
85 $person['site_ids'] = array_filter($person['site_ids'],
86 create_function('$site_id', 'return intval($site_id) > 0;'));
89 if (!empty($person)) {
90 // Look for missing/blank entries
92 foreach ($form as $name => $item) {
93 if ($item['required'] && empty($person[$name])) {
94 $missing[] = $item['title'];
97 if (!empty($missing)) {
99 foreach ($missing as $field) {
100 $error .= "<li>$field field is required.</li>";
106 // N.B.: site_ids and roles are ignored by AddPerson()
107 $person_id = $adm->AddPerson($person);
108 $error = $adm->error();
114 // Add person to requested sites
115 foreach ($person['site_ids'] as $site_id) {
116 $adm->AddPersonToSite($person_id, intval($site_id));
117 $adm->SetPersonPrimarySite($person_id, intval($site_id));
120 // Add requested roles. Always add the user role.
121 $adm->AddRoleToPerson('user', $person_id);
122 if (!empty($person['roles'])) {
123 foreach ($person['roles'] as $role) {
124 $adm->AddRoleToPerson($role, $person_id);
128 // Send an e-mail containing a link back to this page, which will
129 // verify the given e-mail address as valid. PIs can still create
130 // and enable accounts on behalf of their users, they just have to
131 // find and enable the accounts manually after registering them.
132 $adm->VerifyPerson($person_id);
134 // Disable submit button
135 $person['person_id'] = $person_id;
138 $error = $adm->error();
141 if (!empty($error)) {
142 print '<div class="messages error">' . $error . '</div>';
144 print '<div class="messages status">Your registration request has been received. An e-mail has been sent to ';
145 print $person['email'];
146 print ' with further instructions.</div>';
150 $PLC_NAME = htmlspecialchars(PLC_NAME);
152 // E-mail address verified, go ahead and notify the PI (and possibly
153 // support if a PI role was requested) that a registration request was
155 if (!empty($_REQUEST['id']) && !empty($_REQUEST['key'])) {
156 $person_id = intval($_REQUEST['id']);
157 if ($adm->VerifyPerson($person_id, $_REQUEST['key']) != 1) {
158 print '<div class="messages error">' . $adm->error() . '.</div>';
160 $persons = $adm->GetPersons(array($person_id));
161 $person = $persons[0];
163 // Remove the password field from the form so that it is not
164 // highlighted as missing.
165 unset($form['password']);
167 print '<div class="messages status">';
168 print 'Your e-mail address has been verified. ';
169 print 'The PI(s) at your site have been notified of your account registration ';
171 if (in_array('pi', $person['roles'])) {
172 $support = PLC_MAIL_SUPPORT_ADDRESS;
173 print " and should contact <a href=\"mailto:$support\">$PLC_NAME Support <$support></a>. ";
174 print " $PLC_NAME Support will enable your account if authorized by your PI(s).";
176 print ' and are responsible for enabling your account.';
183 $self = $_SERVER['PHP_SELF'];
184 if (!empty($_SERVER['QUERY_STRING'])) {
185 $self .= "?" . $_SERVER['QUERY_STRING'];
191 // cannot register with foreign site
192 $adm->GetSites(array('is_public' => TRUE, 'peer_id' => NULL,'-SORT'=>'name'),
193 array('site_id', 'name','enabled','peer_id'));
197 list($sites, $roles) = $adm->commit();
199 // Prepend invalid site to beginning of list to force user to select a site
200 $sites = array_merge(array(array('site_id' => -1, 'name' => 'Select a site', 'enabled' => TRUE)), $sites);
202 // Drop down selection box for each site
203 function site_option($site) {
206 $site_id = $site['site_id'];
208 if (!empty($person['site_ids']) && in_array($site_id, $person['site_ids'])) {
209 $selected = 'selected="selected"';
214 $option = "<option value=\"$site_id\" $selected";
215 if ( ! $site['enabled'] )
216 $option .= " disabled='disabled'";
218 $option .= htmlspecialchars($site['name']);
219 # Safari/IE do not implement disabled correctly
220 if ( ! $site['enabled'] )
221 $option .= " (pending registration)";
222 $option .= "</option>";
225 $site_options = implode("\n", array_map('site_option', $sites));
227 // Do not tempt users to register for the admin role. Administrators
228 // should register normally, then be granted the admin role by another
229 // admin. Also, all accounts should have the user role (see above).
230 foreach ($roles as $i => $role) {
231 if ($role['name'] == 'admin' || $role['name'] == 'user') {
237 global $standard_roles;
238 $standard_roles = array('user' => 'User',
239 'pi' => 'Principal Investigator',
240 'tech' => 'Technical Contact',
241 'admin' => 'Administrator');
243 // Drop down selection box for each role
244 function role_option($role) {
245 global $standard_roles, $selected_roles;
247 $name = $role['name'];
249 if (!empty($person['roles']) && in_array($name, $person['roles'])) {
250 $selected = 'selected="selected"';
255 $display = array_key_exists($name, $standard_roles) ? $standard_roles[$name] : $name;
257 $option = "<option value=\"$name\" $selected>";
258 $option .= htmlspecialchars($display);
259 $option .= "</option>";
262 $role_options = implode("\n", array_map('role_option', $roles));
264 $self = $_SERVER['PHP_SELF'];
265 if (!empty($_SERVER['QUERY_STRING'])) {
266 $self .= "?" . $_SERVER['QUERY_STRING'];
270 <div class="content">
272 <form action="$self" method="post">
274 <table border="0" cellpadding="5" cellspacing="0">
277 foreach ($form as $name => $item) {
279 if ( ! empty($item['comment'])) {
280 $comment=$item['comment'];
281 print "<tr><td colspan='2'> </td></tr>";
282 print "<tr><td colspan='2'> $comment: </td></tr>";
285 $title = $item['title'];
286 $required = $item['required'] ? '<span class="form-required" title="This field is required.">*</span>' : "";
287 $class = $item['required'] ? "required" : "";
288 if ($item['required'] && !empty($person) && empty($person[$name])) {
295 <td><label class="$class" for="edit-$name">$title: $required</label></td>\n
303 <td><select name="site_ids[]" id="edit-site_ids" class="form-select $class">
311 <td><select name="roles[]" multiple="multiple" id="edit-roles" class="form-select $class">
318 $maxlength = $item['maxlength'];
319 $size = $item['size'];
320 $value = !empty($person[$name]) ? $person[$name] : "";
321 $type = $name == 'password' ? "password" : "text";
323 <td><input type="$type" maxlength="$maxlength" name="$name" id="edit-$name" size="$size" value="$value" class="form-text $class"></td>\n
331 // Do not allow resubmits
332 if (empty($person['person_id'])) {
333 print '<tr><td colspan="2"><input type="submit" name="op" value="Register" class="form-submit" /></td></tr>';
343 include 'plc_footer.php';