2 // $Id: register.php 823 2007-09-07 10:13:27Z thierry $
4 // Site registration and verification form.
6 // Thierry Parmentelat -- INRIA
7 // based on persons/register.php
10 // Get session and API handles
11 require_once 'plc_session.php';
12 global $plc, $api, $adm;
14 // Get sorting functions
15 require_once 'plc_sorts.php';
18 require_once 'plc_drupal.php';
19 drupal_set_title('New Site Registration');
20 include 'plc_header.php';
22 include 'site_form.php';
27 $objectnames = array ('site','pi','tech','address');
29 $site_form = build_site_form(TRUE);
30 $input = parse_form ($site_form, $_REQUEST, $input);
31 $empty_form = $input['is_empty'];
36 $address=$input['address'];
39 // Look for missing/blank entries
40 $error = form_check_required ($site_form, $input);
46 // I considered using begin/commit
47 // but first it was incorrectly reporting errors - which I fixed
48 // second: you need site_id to perform AddSiteAddress
49 // but you cannot write
52 // AddSiteAddress(site_id,..)
53 // because site_id would not be evaluated at the time you use it
55 // and you cannot either write
58 // AddSiteAddress('login_base',...)
59 // because if the first call fails because login_base is already taken,
60 // then you're going to add the new address to the wrong site
62 // the bottom line is, there's no advantage in using begin/commit at all
65 $site['enabled']=FALSE;
66 $site_id=$adm->AddSite($site);
67 $api_error .= $adm->error();
68 if (empty($api_error)) {
69 $verboses [] = "Site created as disabled";
77 // Thierry on august 22 2007
78 // use NotifySupport to send this message, and get rid of the fake account
80 $subject = "Site registration form : new site " . $site['name'];
81 // should use GetMessages and stuff, but I do not trust the way
82 // templates are created in db-config, for upgrades notably
84 We received a site registration form for site name %s
86 To review, please visit https://%s:%d/db/sites/join_request.php?review=t&site_id=%d.
88 $body=sprintf($template,$site['name'],PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id);
89 $adm->NotifySupport($subject,$body);
91 $messages [] = "Your registration request has been received.";
92 $messages [] = "A mail was sent to the operations team, your application should be processed shortly.";
93 $messages [] = "Upon approval, the PI will receive an information e-mail";
94 $messages [] = "Please send a message to " . PLC_MAIL_SUPPORT_ADDRESS . " if this request is not instructed within a few days.";
97 $adm->AddSiteAddress($site_id,$address);
98 $api_error = $adm->error();
99 if (empty($api_error)) {
100 $verboses [] = "Address created";
102 $error .= $api_error;
106 // Thierry 23 august 2007
107 // avoid using a pre-existing federated account
108 $known_pi = $adm->GetPersons(array("email"=>$pi['email'],
109 "peer_id"=>NULL),array("person_id"));
111 $messages [] = " Note: PI was already known";
112 $pi_id=$known_pi[0]['person_id'];
114 $pi['enabled']=FALSE;
115 $pi_id=$adm->AddPerson($pi);
116 $api_error = $adm->error();
117 if (empty($api_error)) {
118 $verboses [] = "PI created as disabled</p>";
120 $error .= $api_error;
123 if ($adm->AddPersonToSite($pi_id,$site_id)) {
124 $verboses [] = "PI attached to new site";
126 if ($adm->AddRoleToPerson('pi',$pi_id)) {
127 $verboses [] = $pi['email'] . " granted PI role</p>";
130 if ($pi['email'] == $tech['email']) {
131 // need to assign tech role so the registration request gets filled properly
132 if ($adm->AddRoleToPerson('tech',$pi_id)) {
133 $verboses [] = $pi['email'] . " granted Tech role</p>";
137 $known_tech = $adm->GetPersons(array("email"=>$tech['email'],
138 "peer_id"=>NULL),array("person_id"));
140 $messages [] = " Note: Tech was already known";
141 $tech_id=$known_tech[0]['person_id'];
143 $tech['enabled']=FALSE;
144 $tech_id=$adm->AddPerson($tech);
145 $api_error = $adm->error();
146 if (empty($api_error)) {
147 $verboses [] = "Tech created as disabled</p>";
149 $error .= $api_error;
152 if ($adm->AddPersonToSite($tech_id,$site_id)) {
153 $verboses [] = "Tech attached to new site";
155 if ($adm->AddRoleToPerson('tech',$tech_id)) {
156 $verboses [] = $tech['email'] . " granted Tech role";
158 if ( ($tech['user-role']) && $adm->AddRoleToPerson('user',$tech_id) ) {
159 $verboses [] = $tech['email'] . " granted User role";
166 if (!empty($messages)) {
167 print '<div class="messages status"><ul>';
168 foreach ($messages as $line) {
174 if ($verbose && !empty($verboses)) {
175 print '<div class="messages status"><ul>';
176 print "<p> Verbose messages</p>";
177 foreach ($verboses as $line) {
183 if (!empty($error)) {
184 print '<div class="messages error">' . $error . '</div>';
186 // to prevent resubmit
187 $site['site_id']="XXX";
191 $self = $_SERVER['PHP_SELF'];
192 if (!empty($_SERVER['QUERY_STRING'])) {
193 $self .= "?" . $_SERVER['QUERY_STRING'];
197 <div class="content">
199 <form action="$self" method="post">
201 <table border="0" width="100%" cellspacing="0" cellpadding="3">
204 // Do not allow resubmits
205 if (empty($site['site_id'])) {
206 print '<tr><td colspan=2 align=center><input type="submit" name="op" value="Register" class="form-submit" /></td></tr>';
209 form_render_table2 ($site_form, $input, ! $empty_form);
211 // Do not allow resubmits
212 if (empty($site['site_id'])) {
213 print '<tr><td colspan=2> </td></tr>';
214 print '<tr><td colspan=2 align=center><input type="submit" name="op" value="Register" class="form-submit" /></td></tr>';
217 print "</table></form></div>";
219 include 'plc_footer.php';