<?php
//
-// Site registration and verification form.
+// Site registration and verification form.
//
-// Thierry Parmentelat -- INRIA
-// based on persons/register.php
+// Thierry Parmentelat -- INRIA
+// based on persons/register.php
//
// Get session and API handles
// begin
// AddSite(..)
// AddSiteAddress('login_base',...)
- // because if the first call fails because login_base is already taken,
+ // because if the first call fails because login_base is already taken,
// then you're going to add the new address to the wrong site
- //
+ //
// the bottom line is, there's no advantage in using begin/commit at all
-
+
// creating the site
$site['enabled']=FALSE;
global $PENDING_CONSORTIUM_ID;
$error .= $api_error;
}
}
-
+
if (empty($error)) {
// Thierry on august 22 2007
// use NotifySupport to send this message, and get rid of the fake account
$subject = "Site registration form : new site " . $site['name'];
- // should use GetMessages and stuff, but I do not trust the way
+ // should use GetMessages and stuff, but I do not trust the way
// templates are created in db-config, for upgrades notably
$template = <<< EOF
We received a site registration form for site name %s
EOF;
$body=sprintf($template,$site['name'],PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id);
$adm->NotifySupport($subject,$body);
-
+
$messages [] = "Your registration request has been received.";
$messages [] = "A mail was sent to the operations team, your application should be processed shortly.";
$messages [] = "Upon approval, the PI will receive an information e-mail";
$adm->AddSiteAddress($site_id,$address);
$api_error = $adm->error();
if (empty($api_error)) {
- $verboses [] = "Address created";
+ $verboses [] = "Address created";
} else {
- $error .= $api_error;
+ $error .= $api_error;
}
}
// Thierry 23 august 2007
// avoid using a pre-existing federated account
$known_pi = $adm->GetPersons(array("email"=>$pi['email'],
- "peer_id"=>NULL),array("person_id"));
+ "peer_id"=>NULL),
+ array("person_id"));
if ($known_pi) {
$messages [] = " Note: PI was already known";
$pi_id=$known_pi[0]['person_id'];
$pi_id=$adm->AddPerson($pi);
$api_error = $adm->error();
if (empty($api_error)) {
- $verboses [] = "PI created as disabled</p>";
+ $verboses [] = "PI created as disabled</p>";
} else {
- $error .= $api_error;
+ $error .= $api_error;
}
}
if ($adm->AddPersonToSite($pi_id,$site_id)) {
if ($adm->AddRoleToPerson('pi',$pi_id)) {
$verboses [] = $pi['email'] . " granted PI role</p>";
}
-
+
if ($pi['email'] == $tech['email']) {
// need to assign tech role so the registration request gets filled properly
if ($adm->AddRoleToPerson('tech',$pi_id)) {
- $verboses [] = $pi['email'] . " granted Tech role</p>";
+ $verboses [] = $pi['email'] . " granted Tech role</p>";
}
} else {
// creating TECH
$known_tech = $adm->GetPersons(array("email"=>$tech['email'],
- "peer_id"=>NULL),array("person_id"));
+ "peer_id"=>NULL),
+ array("person_id"));
// jan-2013 with improvements in plcapi-5.1-6 about managing persons and tags,
// AddPerson has gone more picky and we need to remove some fields
// that no longer are silently ignored by AddPerson
$user_role_required=$tech['user-role'];
unset($tech['user-role']);
if ($known_tech) {
- $messages [] = " Note: Tech was already known";
- $tech_id=$known_tech[0]['person_id'];
+ $messages [] = " Note: Tech was already known";
+ $tech_id=$known_tech[0]['person_id'];
} else {
- $tech['enabled']=FALSE;
- $tech_id=$adm->AddPerson($tech);
- $api_error = $adm->error();
- if (empty($api_error)) {
- $verboses [] = "Tech created as disabled</p>";
- } else {
- $error .= $api_error;
- }
+ $tech['enabled']=FALSE;
+ $tech_id=$adm->AddPerson($tech);
+ $api_error = $adm->error();
+ if (empty($api_error)) {
+ $verboses [] = "Tech created as disabled</p>";
+ } else {
+ $error .= $api_error;
+ }
}
if ($adm->AddPersonToSite($tech_id,$site_id)) {
- $verboses [] = "Tech attached to new site";
+ $verboses [] = "Tech attached to new site";
}
if ($adm->AddRoleToPerson('tech',$tech_id)) {
- $verboses [] = $tech['email'] . " granted Tech role";
+ $verboses [] = $tech['email'] . " granted Tech role";
}
if ( $user_role_required && $adm->AddRoleToPerson('user',$tech_id) ) {
- $verboses [] = $tech['email'] . " granted User role";
+ $verboses [] = $tech['email'] . " granted User role";
}
}
}
-
+
// Show messages
if (!empty($messages)) {
}
print "</ul></div>";
}
-
+
if ($verbose && !empty($verboses)) {
print '<div class="messages status"><ul>';
print "<p> Verbose messages</p>";
}
print "</ul></div>";
}
-
+
if (!empty($error)) {
print '<div class="messages error">' . $error . '</div>';
} else {
<?php
-// $Id$
// Drupalish, but does not use Drupal itself to generate the form
function build_site_form ($register_mode) {
$form = array();
- $form['site:name'] = array('title' => 'Site name', 'required' => TRUE,
- 'maxlength' => 40, 'size' => 20,
- 'comment' => '<span class="bold">Site Information</span>');
- $form['site:login_base'] = array('title' => 'Login base', 'required' => TRUE,
- 'maxlength' => 16, 'size' => 10);
- $form['site:abbreviated_name'] = array('title' => 'Abbreviated name', 'required' => TRUE,
- 'maxlength' => 40, 'size' => 20);
- $form['site:url'] = array('title' => 'URL', 'required' => TRUE,
- 'maxlength' => 128, 'size' => 30);
- $form['site:latitude'] = array('title' => 'Latitude', 'required' => TRUE,
- 'maxlength' => 10, 'size' => 10, 'type' => 'double');
- $form['site:longitude'] = array('title' => 'Longitude', 'required' => TRUE,
- 'maxlength' => 10, 'size' => 10, 'type' => 'double');
-
- $form['pi:first_name'] = array('title' => 'PI First Name', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20,
- 'comment' => '<span class="bold">Principal Investigator Information</span>');
- $form['pi:last_name'] = array('title' => 'PI Last Name', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20);
- $form['pi:title'] = array('title' => 'PI Title', 'required' => FALSE,
- 'maxlength' => 6, 'size' => 6);
- $form['pi:phone'] = array('title' => 'PI Phone', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20);
- $form['pi:email'] = array('title' => 'PI email', 'required' => TRUE,
- 'maxlength' => 40, 'size' => 20);
+ $form['site:name'] = array(
+ 'title' => 'Site name', 'required' => TRUE,
+ 'maxlength' => 40, 'size' => 20,
+ 'comment' => '<span class="bold">Site Information</span>');
+ $form['site:login_base'] = array(
+ 'title' => 'Login base', 'required' => TRUE,
+ 'maxlength' => 16, 'size' => 10);
+ $form['site:abbreviated_name'] = array(
+ 'title' => 'Abbreviated name', 'required' => TRUE,
+ 'maxlength' => 40, 'size' => 20);
+ $form['site:url'] = array(
+ 'title' => 'URL', 'required' => TRUE,
+ 'maxlength' => 128, 'size' => 30);
+ $form['site:latitude'] = array(
+ 'title' => 'Latitude', 'required' => TRUE,
+ 'maxlength' => 10, 'size' => 10, 'type' => 'double');
+ $form['site:longitude'] = array(
+ 'title' => 'Longitude', 'required' => TRUE,
+ 'maxlength' => 10, 'size' => 10, 'type' => 'double');
+
+ $form['pi:first_name'] = array(
+ 'title' => 'PI First Name', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20,
+ 'comment' => '<span class="bold">Principal Investigator Information</span>');
+ $form['pi:last_name'] = array(
+ 'title' => 'PI Last Name', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20);
+ $form['pi:title'] = array(
+ 'title' => 'PI Title', 'required' => FALSE,
+ 'maxlength' => 6, 'size' => 6);
+ $form['pi:phone'] = array(
+ 'title' => 'PI Phone', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20);
+ $form['pi:email'] = array(
+ 'title' => 'PI email', 'required' => TRUE,
+ 'maxlength' => 40, 'size' => 20);
if ($register_mode) {
- $form['pi:password'] = array('title' => 'PI password', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20, 'type' => 'password');
+ $form['pi:password'] = array(
+ 'title' => 'PI password', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20, 'type' => 'password');
}
copyValue("edit-pi:title","edit-tech:title");
copyValue("edit-pi:phone","edit-tech:phone");
copyValue("edit-pi:email","edit-tech:email");
-copyValue("edit-pi:password","edit-tech:password")'
-</input>
+copyValue("edit-pi:password","edit-tech:password")'
+</input>
EOF;
}
- $form['tech:first_name'] = array('title' => 'Tech First Name', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20,
- 'comment' => '<span class="bold">Technical Contact Information</span>' . $fill_from_pi_button);
- $form['tech:last_name'] = array('title' => 'Tech Last Name', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20);
- $form['tech:title'] = array('title' => 'Tech Title', 'required' => FALSE,
- 'maxlength' => 6, 'size' => 6);
- $form['tech:phone'] = array('title' => 'Tech Phone', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20);
- $form['tech:email'] = array('title' => 'Tech email', 'required' => TRUE,
- 'maxlength' => 40, 'size' => 20);
+ $form['tech:first_name'] = array(
+
+ 'title' => 'Tech First Name', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20,
+ 'comment' => '<span class="bold">Technical Contact Information</span>' . $fill_from_pi_button);
+ $form['tech:last_name'] = array(
+ 'title' => 'Tech Last Name', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20);
+ $form['tech:title'] = array(
+ 'title' => 'Tech Title', 'required' => FALSE,
+ 'maxlength' => 6, 'size' => 6);
+ $form['tech:phone'] = array(
+ 'title' => 'Tech Phone', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20);
+ $form['tech:email'] = array(
+ 'title' => 'Tech email', 'required' => TRUE,
+ 'maxlength' => 40, 'size' => 20);
if ($register_mode) {
- $form['tech:password'] = array('title' => 'Tech password', 'required' => TRUE,
- 'maxlength' => 20, 'size' => 20, 'type' => 'password');
- $form['tech:user-role'] = array('type' => 'boolean', 'title' => 'Need user role', 'default' => TRUE);
+ $form['tech:password'] = array(
+ 'title' => 'Tech password', 'required' => TRUE,
+ 'maxlength' => 20, 'size' => 20, 'type' => 'password');
+ $form['tech:user-role'] = array(
+ 'type' => 'boolean', 'title' => 'Need user role', 'default' => TRUE);
}
- $form['address:line1'] = array('title' => 'Address', 'required' => FALSE,
- 'maxlength' => 40, 'size' => 30,
- 'comment' => '<span class="bold">Postal address</span>');
- $form['address:line2'] = array('title' => 'Address (2)', 'required' => FALSE,
- 'maxlength' => 40, 'size' => 30);
- $form['address:line3'] = array('title' => 'Address (3)', 'required' => FALSE,
- 'maxlength' => 40, 'size' => 30);
- $form['address:city'] = array('title' => 'City', 'required' => FALSE,
- 'maxlength' => 20, 'size' => 20);
- $form['address:postalcode'] = array('title' => 'Postal Code', 'required' => FALSE,
- 'maxlength' => 10, 'size' => 10);
+ $form['address:line1'] = array(
+ 'title' => 'Address', 'required' => FALSE,
+ 'maxlength' => 40, 'size' => 30,
+ 'comment' => '<span class="bold">Postal address</span>');
+ $form['address:line2'] = array(
+ 'title' => 'Address (2)', 'required' => FALSE,
+ 'maxlength' => 40, 'size' => 30);
+ $form['address:line3'] = array(
+ 'title' => 'Address (3)', 'required' => FALSE,
+ 'maxlength' => 40, 'size' => 30);
+ $form['address:city'] = array(
+ 'title' => 'City', 'required' => FALSE,
+ 'maxlength' => 20, 'size' => 20);
+ $form['address:postalcode'] = array(
+ 'title' => 'Postal Code', 'required' => FALSE,
+ 'maxlength' => 10, 'size' => 10);
# would have liked it *not* required but it is mandatory in the DB - sigh
- $form['address:state'] = array('title' => 'State', 'required' => FALSE,
- 'maxlength' => 20, 'size' => 20);
- $form['address:country'] = array('title' => 'Country', 'required' => FALSE,
- 'maxlength' => 20, 'size' => 20);
+ $form['address:state'] = array(
+ 'title' => 'State', 'required' => FALSE,
+ 'maxlength' => 20, 'size' => 20);
+ $form['address:country'] = array(
+ 'title' => 'Country', 'required' => FALSE,
+ 'maxlength' => 20, 'size' => 20);
return $form;
}
-// input :
+// input :
// $form : the form as defined above
// $request : usually $_REQUEST
// $input : a dict ('site'=>$site ..)
// implement type conversion
switch ($item['type']) {
case 'double':
- $input[$objname][$field] = doubleval(trim($raw_input));
- break;
+ $input[$objname][$field] = doubleval(trim($raw_input));
+ break;
case 'int':
- $input[$objname][$field] = intval(trim($raw_input));
- break;
+ $input[$objname][$field] = intval(trim($raw_input));
+ break;
case 'boolean':
- $input[$objname][$field] = ($raw_input=="yes");
- break;
+ $input[$objname][$field] = ($raw_input=="yes");
+ break;
case 'password':
case 'raw':
- $input[$objname][$field] = $raw_input;
- break;
+ $input[$objname][$field] = $raw_input;
+ break;
default:
- $input[$objname][$field] = trim($raw_input);
- break;
+ $input[$objname][$field] = trim($raw_input);
+ break;
}
} else {
switch ($item['type']) {
case 'double':
- $input[$objname][$field] = 0.0;
- break;
+ $input[$objname][$field] = 0.0;
+ break;
case 'int':
- $input[$objname][$field] = 0;
- break;
+ $input[$objname][$field] = 0;
+ break;
case 'boolean':
- if (array_key_exists($field,$request)) {
- $input[$objname][$field]=FALSE;
- }
- break;
+ if (array_key_exists($field,$request)) {
+ $input[$objname][$field]=FALSE;
+ }
+ break;
default:
- $input[$objname][$field] = '';
- break;
+ $input[$objname][$field] = '';
+ break;
}
}
}
function form_check_required ($form, $input) {
$missing = array();
foreach ($form as $fullname => $item) {
- list($objname,$field) = explode(":",$fullname);
+ list($objname, $field) = explode(":", $fullname);
if ($item['required'] && empty($input[$objname][$field])) {
$missing[] = $item['title'];
}
}
- if (empty($missing))
+ if (empty($missing))
return "";
$error = "<ul>";
foreach ($missing as $field) {
function form_render_details ($details, $site_form, $input, $outline_missing) {
foreach ($site_form as $fullname => $item) {
-
+
list($objname,$field) = explode(":",$fullname);
-
+
// render the comment field
if ( ! empty($item['comment'])) {
$details->space();
if ($item['type'] == 'boolean') {
// compute boolean default : whether we have this in the request
if (array_key_exists($field,$input[$objname])) {
- $default = $input[$objname][$field] ;
+ $default = $input[$objname][$field] ;
} else { // or not - in which case we use the form default
- $default = ($item['default'] == TRUE);
+ $default = ($item['default'] == TRUE);
}
if ($default) {
- $checkedyes = "checked='checked'";
- $checkedno = "";
+ $checkedyes = "checked='checked'";
+ $checkedno = "";
} else {
- $checkedyes = "";
- $checkedno = "checked='checked'";
+ $checkedyes = "";
+ $checkedno = "checked='checked'";
}
$right_part = <<<EOF
<input type='radio' id="check-$fullname" name="$fullname" value="yes" $checkedyes> Yes
$maxlength = $item['maxlength'];
$size = $item['size'];
$right_part= <<<EOF
-<input type="$type" id="edit-$fullname" name="$fullname" value="$value"
-size="$size" maxlength="$maxlength"
-class="form-text $class" />
+<input type="$type" id="edit-$fullname" name="$fullname" value="$value"
+size="$size" maxlength="$maxlength"
+class="form-text $class" />
EOF;
}