3 // Site registration and verification form.
5 // Thierry Parmentelat -- INRIA
6 // based on persons/register.php
9 // Get session and API handles
10 require_once 'plc_session.php';
11 global $plc, $api, $adm;
14 require_once 'plc_drupal.php';
15 drupal_set_title('New Site Registration');
16 include 'plc_header.php';
18 require_once 'site_form.php';
19 require_once 'details.php';
20 require_once 'nifty.php';
25 $objectnames = array ('site','pi','tech','address');
27 $site_form = build_site_form(TRUE);
28 $input = parse_form ($site_form, $_REQUEST, $input);
29 $empty_form = $input['is_empty'];
34 $address=$input['address'];
36 # allow address to be left out
37 function non_empty_address ($address) {
38 return !empty($address['line1']);
42 // Look for missing/blank entries
43 $error = form_check_required ($site_form, $input);
49 // I considered using begin/commit
50 // but first it was incorrectly reporting errors - which I fixed
51 // second: you need site_id to perform AddSiteAddress
52 // but you cannot write
55 // AddSiteAddress(site_id,..)
56 // because site_id would not be evaluated at the time you use it
58 // and you cannot either write
61 // AddSiteAddress('login_base',...)
62 // because if the first call fails because login_base is already taken,
63 // then you're going to add the new address to the wrong site
65 // the bottom line is, there's no advantage in using begin/commit at all
68 $site['enabled']=FALSE;
69 global $PENDING_CONSORTIUM_ID;
70 $site['ext_consortium_id']=$PENDING_CONSORTIUM_ID;
71 $site_id=$adm->AddSite($site);
72 $api_error .= $adm->error();
73 if (empty($api_error)) {
74 $verboses [] = "Site created as disabled, with ext_consortium_id=".$PENDING_CONSORTIUM_ID;
82 // Thierry on august 22 2007
83 // use NotifySupport to send this message, and get rid of the fake account
85 $subject = "Site registration form : new site " . $site['name'];
86 // should use GetMessages and stuff, but I do not trust the way
87 // templates are created in db-config, for upgrades notably
89 We received a site registration form for site name %s
91 To review, please visit https://%s:%d/db/sites/join_request.php?review=t&site_id=%d.
93 $body=sprintf($template,$site['name'],PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id);
94 $adm->NotifySupport($subject,$body);
96 $messages [] = "Your registration request has been received.";
97 $messages [] = "A mail was sent to the operations team, your application should be processed shortly.";
98 $messages [] = "Upon approval, the PI will receive an information e-mail";
99 $messages [] = "Please send a message to " . PLC_MAIL_SUPPORT_ADDRESS . " if this request is not instructed within a few days.";
102 if (non_empty_address($address)) {
103 $adm->AddSiteAddress($site_id,$address);
104 $api_error = $adm->error();
105 if (empty($api_error)) {
106 $verboses [] = "Address created";
108 $error .= $api_error;
113 // Thierry 23 august 2007
114 // avoid using a pre-existing federated account
115 $known_pi = $adm->GetPersons(array("email"=>$pi['email'],
116 "peer_id"=>NULL),array("person_id"));
118 $messages [] = " Note: PI was already known";
119 $pi_id=$known_pi[0]['person_id'];
121 $pi['enabled']=FALSE;
122 $pi_id=$adm->AddPerson($pi);
123 $api_error = $adm->error();
124 if (empty($api_error)) {
125 $verboses [] = "PI created as disabled</p>";
127 $error .= $api_error;
130 if ($adm->AddPersonToSite($pi_id,$site_id)) {
131 $verboses [] = "PI attached to new site";
133 if ($adm->AddRoleToPerson('pi',$pi_id)) {
134 $verboses [] = $pi['email'] . " granted PI role</p>";
137 if ($pi['email'] == $tech['email']) {
138 // need to assign tech role so the registration request gets filled properly
139 if ($adm->AddRoleToPerson('tech',$pi_id)) {
140 $verboses [] = $pi['email'] . " granted Tech role</p>";
144 $known_tech = $adm->GetPersons(array("email"=>$tech['email'],
145 "peer_id"=>NULL),array("person_id"));
146 // jan-2013 with improvements in plcapi-5.1-6 about managing persons and tags,
147 // AddPerson has gone more picky and we need to remove some fields
148 // that no longer are silently ignored by AddPerson
149 $user_role_required=$tech['user-role'];
150 unset($tech['user-role']);
152 $messages [] = " Note: Tech was already known";
153 $tech_id=$known_tech[0]['person_id'];
155 $tech['enabled']=FALSE;
156 $tech_id=$adm->AddPerson($tech);
157 $api_error = $adm->error();
158 if (empty($api_error)) {
159 $verboses [] = "Tech created as disabled</p>";
161 $error .= $api_error;
164 if ($adm->AddPersonToSite($tech_id,$site_id)) {
165 $verboses [] = "Tech attached to new site";
167 if ($adm->AddRoleToPerson('tech',$tech_id)) {
168 $verboses [] = $tech['email'] . " granted Tech role";
170 if ( $user_role_required && $adm->AddRoleToPerson('user',$tech_id) ) {
171 $verboses [] = $tech['email'] . " granted User role";
178 if (!empty($messages)) {
179 print '<div class="messages status"><ul>';
180 foreach ($messages as $line) {
186 if ($verbose && !empty($verboses)) {
187 print '<div class="messages status"><ul>';
188 print "<p> Verbose messages</p>";
189 foreach ($verboses as $line) {
195 if (!empty($error)) {
196 print '<div class="messages error">' . $error . '</div>';
198 // to prevent resubmit
199 $site['site_id']="XXX";
203 $self = $_SERVER['PHP_SELF'];
204 if (!empty($_SERVER['QUERY_STRING'])) {
205 $self .= "?" . $_SERVER['QUERY_STRING'];
209 <div class="content">
211 <form action="$self" method="post">
215 $nifty=new PlekitNifty ('register','site-register','medium');
217 $details = new PlekitDetails(TRUE);
220 $register_button='<input type="submit" name="op" value="Register" class="form-submit" />';
222 // Do not allow resubmits
223 if (empty($site['site_id'])) {
224 $details->tr($register_button,'center');
227 form_render_details ($details, $site_form, $input, ! $empty_form);
229 // Do not allow resubmits
230 if (empty($site['site_id'])) {
233 $details->tr($register_button,'center');
238 print "</form></div>";
240 include 'plc_footer.php';