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;
15 require_once 'plc_drupal.php';
16 drupal_set_title('New Site Registration');
17 include 'plc_header.php';
19 require_once 'site_form.php';
20 require_once 'details.php';
21 require_once 'nifty.php';
26 $objectnames = array ('site','pi','tech','address');
28 $site_form = build_site_form(TRUE);
29 $input = parse_form ($site_form, $_REQUEST, $input);
30 $empty_form = $input['is_empty'];
35 $address=$input['address'];
37 # allow address to be left out
38 function non_empty_address ($address) {
39 return !empty($address['line1']);
43 // Look for missing/blank entries
44 $error = form_check_required ($site_form, $input);
50 // I considered using begin/commit
51 // but first it was incorrectly reporting errors - which I fixed
52 // second: you need site_id to perform AddSiteAddress
53 // but you cannot write
56 // AddSiteAddress(site_id,..)
57 // because site_id would not be evaluated at the time you use it
59 // and you cannot either write
62 // AddSiteAddress('login_base',...)
63 // because if the first call fails because login_base is already taken,
64 // then you're going to add the new address to the wrong site
66 // the bottom line is, there's no advantage in using begin/commit at all
69 $site['enabled']=FALSE;
70 global $PENDING_CONSORTIUM_ID;
71 $site['ext_consortium_id']=$PENDING_CONSORTIUM_ID;
72 $site_id=$adm->AddSite($site);
73 $api_error .= $adm->error();
74 if (empty($api_error)) {
75 $verboses [] = "Site created as disabled, with ext_consortium_id=".$PENDING_CONSORTIUM_ID;
83 // Thierry on august 22 2007
84 // use NotifySupport to send this message, and get rid of the fake account
86 $subject = "Site registration form : new site " . $site['name'];
87 // should use GetMessages and stuff, but I do not trust the way
88 // templates are created in db-config, for upgrades notably
90 We received a site registration form for site name %s
92 To review, please visit https://%s:%d/db/sites/join_request.php?review=t&site_id=%d.
94 $body=sprintf($template,$site['name'],PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id);
95 $adm->NotifySupport($subject,$body);
97 $messages [] = "Your registration request has been received.";
98 $messages [] = "A mail was sent to the operations team, your application should be processed shortly.";
99 $messages [] = "Upon approval, the PI will receive an information e-mail";
100 $messages [] = "Please send a message to " . PLC_MAIL_SUPPORT_ADDRESS . " if this request is not instructed within a few days.";
103 if (non_empty_address($address)) {
104 $adm->AddSiteAddress($site_id,$address);
105 $api_error = $adm->error();
106 if (empty($api_error)) {
107 $verboses [] = "Address created";
109 $error .= $api_error;
114 // Thierry 23 august 2007
115 // avoid using a pre-existing federated account
116 $known_pi = $adm->GetPersons(array("email"=>$pi['email'],
117 "peer_id"=>NULL),array("person_id"));
119 $messages [] = " Note: PI was already known";
120 $pi_id=$known_pi[0]['person_id'];
122 $pi['enabled']=FALSE;
123 $pi_id=$adm->AddPerson($pi);
124 $api_error = $adm->error();
125 if (empty($api_error)) {
126 $verboses [] = "PI created as disabled</p>";
128 $error .= $api_error;
131 if ($adm->AddPersonToSite($pi_id,$site_id)) {
132 $verboses [] = "PI attached to new site";
134 if ($adm->AddRoleToPerson('pi',$pi_id)) {
135 $verboses [] = $pi['email'] . " granted PI role</p>";
138 if ($pi['email'] == $tech['email']) {
139 // need to assign tech role so the registration request gets filled properly
140 if ($adm->AddRoleToPerson('tech',$pi_id)) {
141 $verboses [] = $pi['email'] . " granted Tech role</p>";
145 $known_tech = $adm->GetPersons(array("email"=>$tech['email'],
146 "peer_id"=>NULL),array("person_id"));
148 $messages [] = " Note: Tech was already known";
149 $tech_id=$known_tech[0]['person_id'];
151 $tech['enabled']=FALSE;
152 $tech_id=$adm->AddPerson($tech);
153 $api_error = $adm->error();
154 if (empty($api_error)) {
155 $verboses [] = "Tech created as disabled</p>";
157 $error .= $api_error;
160 if ($adm->AddPersonToSite($tech_id,$site_id)) {
161 $verboses [] = "Tech attached to new site";
163 if ($adm->AddRoleToPerson('tech',$tech_id)) {
164 $verboses [] = $tech['email'] . " granted Tech role";
166 if ( ($tech['user-role']) && $adm->AddRoleToPerson('user',$tech_id) ) {
167 $verboses [] = $tech['email'] . " granted User role";
174 if (!empty($messages)) {
175 print '<div class="messages status"><ul>';
176 foreach ($messages as $line) {
182 if ($verbose && !empty($verboses)) {
183 print '<div class="messages status"><ul>';
184 print "<p> Verbose messages</p>";
185 foreach ($verboses as $line) {
191 if (!empty($error)) {
192 print '<div class="messages error">' . $error . '</div>';
194 // to prevent resubmit
195 $site['site_id']="XXX";
199 $self = $_SERVER['PHP_SELF'];
200 if (!empty($_SERVER['QUERY_STRING'])) {
201 $self .= "?" . $_SERVER['QUERY_STRING'];
205 <div class="content">
207 <form action="$self" method="post">
211 $nifty=new PlekitNifty ('register','site-register','medium');
213 $details = new PlekitDetails(TRUE);
216 $register_button='<input type="submit" name="op" value="Register" class="form-submit" />';
218 // Do not allow resubmits
219 if (empty($site['site_id'])) {
220 $details->tr($register_button,'center');
223 form_render_details ($details, $site_form, $input, ! $empty_form);
225 // Do not allow resubmits
226 if (empty($site['site_id'])) {
229 $details->tr($register_button,'center');
234 print "</form></div>";
236 include 'plc_footer.php';