-
<?php
// $Id$
//
// Print header
require_once 'plc_drupal.php';
-drupal_set_title('Account Registration');
include 'plc_header.php';
+require_once 'plc_functions.php';
+require_once 'nifty.php';
+require_once 'details.php';
+
+drupal_set_title('Account Registration');
+
// Drupalish, but does not use Drupal itself to generate the form
-$form = array();
-$form['first_name'] = array('title' => 'First name', 'required' => TRUE,
+global $person_form;
+
+$person_form = array();
+$person_form['first_name'] = array('title' => 'First name', 'required' => TRUE,
'maxlength' => 60, 'size' => 15);
-$form['last_name'] = array('title' => 'Last name', 'required' => TRUE,
+$person_form['last_name'] = array('title' => 'Last name', 'required' => TRUE,
'maxlength' => 60, 'size' => 15);
-$form['title'] = array('title' => 'Title', 'required' => FALSE,
+$person_form['title'] = array('title' => 'Title', 'required' => FALSE,
'maxlength' => 60, 'size' => 5);
-$form['phone'] = array('title' => 'Telephone', 'required' => FALSE,
+$person_form['phone'] = array('title' => 'Telephone', 'required' => FALSE,
'maxlength' => 60, 'size' => 20);
-$form['email'] = array('title' => 'E-mail', 'required' => TRUE,
+$person_form['email'] = array('title' => 'E-mail', 'required' => TRUE,
'maxlength' => 60, 'size' => 30);
-$form['password'] = array('title' => 'Password', 'required' => TRUE,
+$person_form['password'] = array('title' => 'Password', 'required' => TRUE,
'maxlength' => 60, 'size' => 20);
-$form['site_ids'] = array('title' => 'Site', 'required' => TRUE);
-$form['roles'] = array('title' => 'Additional Roles', 'required' => FALSE);
+$person_form['site_ids'] = array('title' => 'Site', 'required' => TRUE);
+if (0)
+ $person_form['roles'] = array('title' => 'Additional Roles', 'required' => FALSE);
//////////////////// additional messages
-$form['email']['comment'] = <<< EOF
+$person_form['email']['comment'] = <<< EOF
Your <b>E-mail</b> address must be able to receive e-mail and will be
used as your $PLC_NAME username
EOF;
-$form['site_ids']['comment'] = <<< EOF
+$person_form['site_ids']['comment'] = <<< EOF
Select the site where you belong
EOF;
-$form['roles']['comment'] = <<< EOF
+if (0)
+ $person_form['roles']['comment'] = <<< EOF
Do not select the <b>Principal Investigator</b> or <b>Technical
Contact</b> roles unless you have spoken with the current PI of your
site, and you intend to assume either or both of these roles.
<br> Use Command-Clic to unselect or for multiple selection
EOF;
-////////////////////
+//////////////////// parse form values and store in $person
global $person;
$person = array();
-foreach ($form as $name => $item) {
+foreach ($person_form as $name => $item) {
if (!empty($_REQUEST[$name])) {
$person[$name] = $_REQUEST[$name];
}
create_function('$site_id', 'return intval($site_id) > 0;'));
}
-if (!empty($person)) {
+//////////////////// minimal checking
+function check_form ($person) {
+ global $person_form;
+ global $adm;
+
// Look for missing/blank entries
$missing = array();
- foreach ($form as $name => $item) {
+ foreach ($person_form as $name => $item) {
if ($item['required'] && empty($person[$name])) {
$missing[] = $item['title'];
}
}
+
+ // missing fields
if (!empty($missing)) {
- $error = "<ul>";
- foreach ($missing as $field) {
- $error .= "<li>$field field is required.</li>";
- }
- $error .= "</ul>";
+ $warnings=array();
+ foreach ($missing as $field) $warnings []= "$field field is required.";
+ print html_div(plc_itemize($warnings),"messages error");
+ return FALSE;
+ }
+
+ // check that the email address is not already used on this peer
+ $email=$person['email'];
+ $already = $adm->GetPersons ( array('email'=>$person['email'],'peer_id'=>NULL) );
+ if ( ! empty ($already) ) {
+ print html_div(plc_itemize(array("Email $email already used !")),"messages error");
+ return FALSE;
}
- if (empty($error)) {
- // N.B.: site_ids and roles are ignored by AddPerson()
- $person_id = $adm->AddPerson($person);
- $error = $adm->error();
- }
+ return TRUE;
+}
+
+//////////////////// perform api calls
+function register_person ($person) {
+
+ global $adm;
+
+ $errors = errors_init ();
- if (empty($error)) {
+ // N.B.: site_ids and roles are ignored by AddPerson()
+ $person_id = $adm->AddPerson($person);
+ $errors = errors_record ($adm,$errors);
+
+ if (empty($errors)) {
$adm->begin();
// Add person to requested sites
$person['person_id'] = $person_id;
$adm->commit();
- $error = $adm->error();
+ $errors = errors_record ($adm,$errors);
}
- if (!empty($error)) {
- print '<div class="messages error">' . $error . '</div>';
+ if (!empty($errors)) {
+ errors_display($errors);
} else {
- print '<div class="messages status">Your registration request has been received. An e-mail has been sent to ';
- print $person['email'];
- print ' with further instructions.</div>';
+ $email=$person['email'];
+ $text="Your registration request has been received. An e-mail has been sent to $email with further instructions.";
+ print html_div($text,"messages status");
}
}
+////////////////////
+if (!empty($person) && check_form ($person))
+ register_person($person);
+
$PLC_NAME = htmlspecialchars(PLC_NAME);
// E-mail address verified, go ahead and notify the PI (and possibly
if (!empty($_REQUEST['id']) && !empty($_REQUEST['key'])) {
$person_id = intval($_REQUEST['id']);
if ($adm->VerifyPerson($person_id, $_REQUEST['key']) != 1) {
- print '<div class="messages error">' . $adm->error() . '.</div>';
+ plc_error($adm->error());
} else {
$persons = $adm->GetPersons(array($person_id));
$person = $persons[0];
// Remove the password field from the form so that it is not
// highlighted as missing.
- unset($form['password']);
+ unset($person_form['password']);
- print '<div class="messages status">';
- print 'Your e-mail address has been verified. ';
- print 'The PI(s) at your site have been notified of your account registration ';
+ $messages = array();
+ $messages []= 'Your e-mail address has been verified. ';
+ $messages []= 'The PI(s) at your site have been notified of your account registration ';
- if (in_array('pi', $person['roles'])) {
- $support = PLC_MAIL_SUPPORT_ADDRESS;
- print " and should contact <a href=\"mailto:$support\">$PLC_NAME Support <$support></a>. ";
- print " $PLC_NAME Support will enable your account if authorized by your PI(s).";
+ if (! in_array('pi', $person['roles'])) {
+ $messages []= 'They are responsible for enabling your account.';
} else {
- print ' and are responsible for enabling your account.';
+ $support = PLC_MAIL_SUPPORT_ADDRESS;
+ $messages []= "They should contact <a href=\"mailto:$support\">$PLC_NAME Support <$support></a>. ";
+ $messages []= "$PLC_NAME Support will enable your account once authorized by your PI(s).";
}
- print '</div>';
+ plc_itemize($messages,"messages status");
}
}
-$self = $_SERVER['PHP_SELF'];
-if (!empty($_SERVER['QUERY_STRING'])) {
- $self .= "?" . $_SERVER['QUERY_STRING'];
-}
-
$adm->begin();
// All defined sites
$selected = "";
}
- $option = "<option value=\"$site_id\" $selected";
+ $option = "<option value='$site_id' $selected";
if ( ! $site['enabled'] )
$option .= " disabled='disabled'";
$option .= ">";
}
$role_options = implode("\n", array_map('role_option', $roles));
-$self = $_SERVER['PHP_SELF'];
-if (!empty($_SERVER['QUERY_STRING'])) {
- $self .= "?" . $_SERVER['QUERY_STRING'];
-}
-
-print <<<EOF
-<div class="content">
-<form action="$self" method="post">
+$nifty=new PlekitNifty ('register','person-register','medium');
+$nifty->start();
+$details = new PlekitDetails(TRUE);
+$details -> start();
+$details->form_start(l_person_register(),array());
-<table border="0" cellpadding="5" cellspacing="0">
-EOF;
+// Do not allow resubmits
+$register_button="<input type='submit' name='op' value='Register' class='form-submit' />";
+if (empty($person['person_id'])) {
+ $details->tr($register_button,'center');
+ $details->space();
+}
-foreach ($form as $name => $item) {
+foreach ($person_form as $name => $item) {
if ( ! empty($item['comment'])) {
- $comment=$item['comment'];
- print "<tr><td colspan='2'> </td></tr>";
- print "<tr><td colspan='2'> $comment: </td></tr>";
+ $details->space();
+ $details->tr($item['comment'] . ":");
}
$title = $item['title'];
}
// Label part
- print "<tr>";
- print <<<EOF
- <td><label class="$class" for="edit-$name">$title: $required</label></td>\n
-EOF;
+ $left_part = "<label class='$class' for='edit-$name'>$title: $required</label>";
// input part
switch ($name) {
case 'site_ids':
- print <<<EOF
- <td><select name="site_ids[]" id="edit-site_ids" class="form-select $class">
- $site_options
- </select></td>\n
-EOF;
+ $right_part= "<select name='site_ids[]' id='edit-site_ids' class='form-select $class'> $site_options </select>";
break;
case 'roles':
- print <<<EOF
- <td><select name="roles[]" multiple="multiple" id="edit-roles" class="form-select $class">
- $role_options
- </select></td>\n
-EOF;
+ $right_part="";
+ if (0) { /* Not letting users select PI or Tech any more. Its only lead to confusion and abuse. */
+ $right_part = "<select name='roles[]' multiple='multiple' id='edit-roles' class='form-select $class'> $role_options </select>";
+ }
break;
default:
$size = $item['size'];
$value = !empty($person[$name]) ? $person[$name] : "";
$type = $name == 'password' ? "password" : "text";
- print <<<EOF
- <td><input type="$type" maxlength="$maxlength" name="$name" id="edit-$name" size="$size" value="$value" class="form-text $class"></td>\n
-EOF;
-
+ $right_part = "<input type='$type' maxlength='$maxlength' name='$name' id='edit-$name' size='$size' value='$value' class='form-text $class'>";
+ break;
}
- print "</tr>\n";
+ $details->th_td($left_part,$right_part);
}
// Do not allow resubmits
if (empty($person['person_id'])) {
- print '<tr><td colspan="2"><input type="submit" name="op" value="Register" class="form-submit" /></td></tr>';
+ $details->space();
+ $details->tr($register_button,'center');
}
-print <<<EOF
-</table>
-
-</form>
-</div>
-EOF;
+$details->form_end();
+$details->end();
+$nifty->end();
include 'plc_footer.php';